Compare commits
42 Commits
crunchyman
...
direct-fun
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
465ae252f0 | ||
|
|
140bd3d265 | ||
|
|
5ed2120ee6 | ||
|
|
34c980ee51 | ||
|
|
e88682f881 | ||
|
|
59208ab7a9 | ||
|
|
a86e9affc5 | ||
|
|
6403e96ef9 | ||
|
|
51919950f1 | ||
|
|
39efd11979 | ||
|
|
65e7886506 | ||
|
|
b8e55dd612 | ||
|
|
819fc5d2f7 | ||
|
|
6ec892b2c1 | ||
|
|
08589b2796 | ||
|
|
d2a5f0e6a9 | ||
|
|
e1e3e31998 | ||
|
|
c414d50bdf | ||
|
|
2c63742a85 | ||
|
|
729e033fef | ||
|
|
69e0b3c393 | ||
|
|
da95466ee1 | ||
|
|
4f68bf3b47 | ||
|
|
12519946b4 | ||
|
|
709ea63350 | ||
|
|
ca3d54f7d6 | ||
|
|
8c5d609c9c | ||
|
|
b78535ac19 | ||
|
|
cfe3ba91e8 | ||
|
|
34501878b2 | ||
|
|
af9421b9ae | ||
|
|
42bf897f81 | ||
|
|
5e01399dca | ||
|
|
e6fe5dac85 | ||
|
|
66f16870c6 | ||
|
|
01a5be25a8 | ||
|
|
4386e74ed2 | ||
|
|
5d3d66ee64 | ||
|
|
bf38baf858 | ||
|
|
ab6746a0c0 | ||
|
|
c02483bc41 | ||
|
|
3148b57f1b |
5
.changeset/all-parks-sort.md
Normal file
5
.changeset/all-parks-sort.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'task-master-ai': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
- Fix expand-all command bugs that caused NaN errors with --all option and JSON formatting errors with research enabled. Improved error handling to provide clear feedback when subtask generation fails, including task IDs and actionable suggestions.
|
||||||
5
.changeset/brave-doors-open.md
Normal file
5
.changeset/brave-doors-open.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'task-master-ai': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Ensures add-task also has manual creation flags like --title/-t, --description/-d etc.
|
||||||
5
.changeset/happy-snails-train.md
Normal file
5
.changeset/happy-snails-train.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'task-master-ai': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix threshold parameter validation and testing for analyze-complexity.
|
||||||
5
.changeset/silly-horses-grin.md
Normal file
5
.changeset/silly-horses-grin.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'task-master-ai': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Adjusts the taskmaster.mdc rules for init and parse-prd so the LLM correctly reaches for the next steps rather than trying to reinitialize or access tasks not yet created until PRD has been parsed."
|
||||||
11
.changeset/thirty-items-kiss.md
Normal file
11
.changeset/thirty-items-kiss.md
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
'task-master-ai': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Two improvements to MCP tools:
|
||||||
|
|
||||||
|
1. Adjusts the response sent to the MCP client for `initialize-project` tool so it includes an explicit `next_steps` object. This is in an effort to reduce variability in what the LLM chooses to do as soon as the confirmation of initialized project. Instead of arbitrarily looking for tasks, it will know that a PRD is required next and will steer the user towards that before reaching for the parse-prd command.
|
||||||
|
|
||||||
|
2. Updates the `parse_prd` tool parameter description to explicitly mention support for .md file formats, clarifying that users can provide PRD documents in various text formats including Markdown.
|
||||||
|
|
||||||
|
3. Updates the `parse_prd` tool `numTasks` param description to encourage the LLM agent to use a number of tasks to break down the PRD into that is logical relative to project complexity.
|
||||||
@@ -2,6 +2,36 @@
|
|||||||
"task-master-ai": patch
|
"task-master-ai": patch
|
||||||
---
|
---
|
||||||
|
|
||||||
|
- **Major Usability & Stability Enhancements:**
|
||||||
|
- Taskmaster can now be seamlessly used either via the globally installed `task-master` CLI (npm package) or directly via the MCP server (e.g., within Cursor). Onboarding/initialization is supported through both methods.
|
||||||
|
- MCP implementation is now complete and stable, making it the preferred method for integrated environments.
|
||||||
|
- **Bug Fixes & Reliability:**
|
||||||
|
- Fixed MCP server invocation issue in `mcp.json` shipped with `task-master init`.
|
||||||
|
- Resolved issues with CLI error messages for flags and unknown commands, added confirmation prompts for destructive actions (e.g., `remove-task`).
|
||||||
|
- Numerous other CLI and MCP tool bugs fixed across the suite (details may be in other changesets like `@all-parks-sort.md`).
|
||||||
|
- **Core Functionality & Commands:**
|
||||||
|
- Added complete `remove-task` functionality for permanent task deletion.
|
||||||
|
- Implemented `initialize_project` MCP tool for easier setup in integrated environments.
|
||||||
|
- Introduced AsyncOperationManager for handling long-running operations (e.g., `expand`, `analyze`) in the background via MCP, with status checking.
|
||||||
|
- **Interface & Configuration:**
|
||||||
|
- Renamed MCP tools for intuitive usage (`list-tasks` → `get-tasks`, `show-task` → `get-task`).
|
||||||
|
- Added binary alias `task-master-mcp-server`.
|
||||||
|
- Clarified environment configuration: `.env` for npm package, `.cursor/mcp.json` for MCP.
|
||||||
|
- Updated model configurations (context window, temperature, defaults) for improved performance/consistency.
|
||||||
|
- **Internal Refinements & Fixes:**
|
||||||
|
- Refactored AI tool patterns, implemented Logger Wrapper, fixed critical issues in `analyze-project-complexity`, `update-task`, `update-subtask`, `set-task-status`, `update`, `expand-task`, `parse-prd`, `expand-all`.
|
||||||
|
- Standardized and improved silent mode implementation across MCP tools to prevent JSON response issues.
|
||||||
|
- Improved parameter handling and project root detection for MCP tools.
|
||||||
|
- Centralized AI client utilities and refactored AI services.
|
||||||
|
- Optimized `get-task` MCP response payload.
|
||||||
|
- **Dependency & Licensing:**
|
||||||
|
- Removed dependency on non-existent package `@model-context-protocol/sdk`.
|
||||||
|
- Updated license to MIT + Commons Clause v1.0.
|
||||||
|
- **Documentation & UI:**
|
||||||
|
- Added comprehensive `taskmaster.mdc` command/tool reference and other rule updates (specific rule adjustments may be in other changesets like `@silly-horses-grin.md`).
|
||||||
|
- Enhanced CLI progress bars and status displays. Added "cancelled" status.
|
||||||
|
- Updated README, added tutorial/examples guide, supported client list documentation.
|
||||||
|
|
||||||
- Adjusts the MCP server invokation in the mcp.json we ship with `task-master init`. Fully functional now.
|
- 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`
|
- 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
|
- Add additional binary alias: `task-master-mcp-server` pointing to the same MCP server script
|
||||||
|
|||||||
@@ -2,15 +2,13 @@
|
|||||||
"mcpServers": {
|
"mcpServers": {
|
||||||
"taskmaster-ai": {
|
"taskmaster-ai": {
|
||||||
"command": "node",
|
"command": "node",
|
||||||
"args": [
|
"args": ["./mcp-server/server.js"],
|
||||||
"./mcp-server/server.js"
|
|
||||||
],
|
|
||||||
"env": {
|
"env": {
|
||||||
"ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE",
|
"ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE",
|
||||||
"PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE",
|
"PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE",
|
||||||
"MODEL": "claude-3-7-sonnet-20250219",
|
"MODEL": "claude-3-7-sonnet-20250219",
|
||||||
"PERPLEXITY_MODEL": "sonar-pro",
|
"PERPLEXITY_MODEL": "sonar-pro",
|
||||||
"MAX_TOKENS": 128000,
|
"MAX_TOKENS": 64000,
|
||||||
"TEMPERATURE": 0.2,
|
"TEMPERATURE": 0.2,
|
||||||
"DEFAULT_SUBTASKS": 5,
|
"DEFAULT_SUBTASKS": 5,
|
||||||
"DEFAULT_PRIORITY": "medium"
|
"DEFAULT_PRIORITY": "medium"
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ alwaysApply: false
|
|||||||
- **Purpose**: Defines and registers all CLI commands using Commander.js.
|
- **Purpose**: Defines and registers all CLI commands using Commander.js.
|
||||||
- **Responsibilities** (See also: [`commands.mdc`](mdc:.cursor/rules/commands.mdc)):
|
- **Responsibilities** (See also: [`commands.mdc`](mdc:.cursor/rules/commands.mdc)):
|
||||||
- Parses command-line arguments and options.
|
- Parses command-line arguments and options.
|
||||||
- Invokes appropriate functions from other modules to execute commands.
|
- Invokes appropriate functions from other modules to execute commands (e.g., calls `initializeProject` from `init.js` for the `init` command).
|
||||||
- Handles user input and output related to command execution.
|
- Handles user input and output related to command execution.
|
||||||
- Implements input validation and error handling for CLI commands.
|
- Implements input validation and error handling for CLI commands.
|
||||||
- **Key Components**:
|
- **Key Components**:
|
||||||
- `programInstance` (Commander.js `Command` instance): Manages command definitions.
|
- `programInstance` (Commander.js `Command` instance): Manages command definitions.
|
||||||
- `registerCommands(programInstance)`: Function to register all application commands.
|
- `registerCommands(programInstance)`: Function to register all application commands.
|
||||||
- Command action handlers: Functions executed when a specific command is invoked.
|
- Command action handlers: Functions executed when a specific command is invoked, delegating to core modules.
|
||||||
|
|
||||||
- **[`task-manager.js`](mdc:scripts/modules/task-manager.js): Task Data Management**
|
- **[`task-manager.js`](mdc:scripts/modules/task-manager.js): Task Data Management**
|
||||||
- **Purpose**: Manages task data, including loading, saving, creating, updating, deleting, and querying tasks.
|
- **Purpose**: Manages task data, including loading, saving, creating, updating, deleting, and querying tasks.
|
||||||
@@ -148,10 +148,23 @@ alwaysApply: false
|
|||||||
- Robust error handling for background tasks
|
- Robust error handling for background tasks
|
||||||
- **Usage**: Used for CPU-intensive operations like task expansion and PRD parsing
|
- **Usage**: Used for CPU-intensive operations like task expansion and PRD parsing
|
||||||
|
|
||||||
|
- **[`init.js`](mdc:scripts/init.js): Project Initialization Logic**
|
||||||
|
- **Purpose**: Contains the core logic for setting up a new Task Master project structure.
|
||||||
|
- **Responsibilities**:
|
||||||
|
- Creates necessary directories (`.cursor/rules`, `scripts`, `tasks`).
|
||||||
|
- Copies template files (`.env.example`, `.gitignore`, rule files, `dev.js`, etc.).
|
||||||
|
- Creates or merges `package.json` with required dependencies and scripts.
|
||||||
|
- Sets up MCP configuration (`.cursor/mcp.json`).
|
||||||
|
- Optionally initializes a git repository and installs dependencies.
|
||||||
|
- Handles user prompts for project details *if* called without skip flags (`-y`).
|
||||||
|
- **Key Function**:
|
||||||
|
- `initializeProject(options)`: The main function exported and called by the `init` command's action handler in [`commands.js`](mdc:scripts/modules/commands.js). It receives parsed options directly.
|
||||||
|
- **Note**: This script is used as a module and no longer handles its own argument parsing or direct execution via a separate `bin` file.
|
||||||
|
|
||||||
- **Data Flow and Module Dependencies**:
|
- **Data Flow and Module Dependencies**:
|
||||||
|
|
||||||
- **Commands Initiate Actions**: User commands entered via the CLI (handled by [`commands.js`](mdc:scripts/modules/commands.js)) are the entry points for most operations.
|
- **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 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.
|
- **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.
|
||||||
- **UI for Presentation**: [`ui.js`](mdc:scripts/modules/ui.js) is used by command handlers and task/dependency managers to display information to the user. UI functions primarily consume data and format it for output, without modifying core application state.
|
- **UI for Presentation**: [`ui.js`](mdc:scripts/modules/ui.js) is used by command handlers and task/dependency managers to display information to the user. UI functions primarily consume data and format it for output, without modifying core application state.
|
||||||
- **Utilities for Common Tasks**: [`utils.js`](mdc:scripts/modules/utils.js) provides helper functions used by all other modules for configuration, logging, file operations, and common data manipulations.
|
- **Utilities for Common Tasks**: [`utils.js`](mdc:scripts/modules/utils.js) provides helper functions used by all other modules for configuration, logging, file operations, and common data manipulations.
|
||||||
- **AI Services Integration**: AI functionalities (complexity analysis, task expansion, PRD parsing) are invoked from [`task-manager.js`](mdc:scripts/modules/task-manager.js) and potentially [`commands.js`](mdc:scripts/modules/commands.js), likely using functions that would reside in a dedicated `ai-services.js` module or be integrated within `utils.js` or `task-manager.js`.
|
- **AI Services Integration**: AI functionalities (complexity analysis, task expansion, PRD parsing) are invoked from [`task-manager.js`](mdc:scripts/modules/task-manager.js) and potentially [`commands.js`](mdc:scripts/modules/commands.js), likely using functions that would reside in a dedicated `ai-services.js` module or be integrated within `utils.js` or `task-manager.js`.
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ While this document details the implementation of Task Master's **CLI commands**
|
|||||||
programInstance
|
programInstance
|
||||||
.command('command-name')
|
.command('command-name')
|
||||||
.description('Clear, concise description of what the command does')
|
.description('Clear, concise description of what the command does')
|
||||||
.option('-s, --short-option <value>', 'Option description', 'default value')
|
.option('-o, --option <value>', 'Option description', 'default value')
|
||||||
.option('--long-option <value>', 'Option description')
|
.option('--long-option <value>', 'Option description')
|
||||||
.action(async (options) => {
|
.action(async (options) => {
|
||||||
// Command implementation
|
// Command implementation
|
||||||
@@ -34,7 +34,8 @@ While this document details the implementation of Task Master's **CLI commands**
|
|||||||
- **Command Handler Organization**:
|
- **Command Handler Organization**:
|
||||||
- ✅ DO: Keep action handlers concise and focused
|
- ✅ DO: Keep action handlers concise and focused
|
||||||
- ✅ DO: Extract core functionality to appropriate modules
|
- ✅ DO: Extract core functionality to appropriate modules
|
||||||
- ✅ DO: Include validation for required parameters
|
- ✅ 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.
|
||||||
- ❌ DON'T: Implement business logic in command handlers
|
- ❌ DON'T: Implement business logic in command handlers
|
||||||
|
|
||||||
## Best Practices for Removal/Delete Commands
|
## Best Practices for Removal/Delete Commands
|
||||||
|
|||||||
@@ -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`)
|
* `addAliases`: `Add shell aliases (tm, taskmaster) (default: false).` (CLI: `--aliases`)
|
||||||
* `yes`: `Skip prompts and use defaults/provided arguments (default: false).` (CLI: `-y, --yes`)
|
* `yes`: `Skip prompts and use defaults/provided arguments (default: false).` (CLI: `-y, --yes`)
|
||||||
* **Usage:** Run this once at the beginning of a new project, typically via an integrated tool like Cursor. Operates on the current working directory of the MCP server.
|
* **Usage:** Run this once at the beginning of a new project, typically via an integrated tool like Cursor. Operates on the current working directory of the MCP server.
|
||||||
|
* **Important:** Once complete, you *MUST* parse a prd in order to generate tasks. There will be no tasks files until then. The next step after initializing should be to create a PRD using the example PRD in scripts/example_prd.txt.
|
||||||
|
|
||||||
### 2. Parse PRD (`parse_prd`)
|
### 2. Parse PRD (`parse_prd`)
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ This document provides a detailed reference for interacting with Taskmaster, cov
|
|||||||
* `force`: `Use this to allow Taskmaster to overwrite an existing 'tasks.json' without asking for confirmation.` (CLI: `-f, --force`)
|
* `force`: `Use this to allow Taskmaster to overwrite an existing 'tasks.json' without asking for confirmation.` (CLI: `-f, --force`)
|
||||||
* **Usage:** Useful for bootstrapping a project from an existing requirements document.
|
* **Usage:** Useful for bootstrapping a project from an existing requirements document.
|
||||||
* **Notes:** Task Master will strictly adhere to any specific requirements mentioned in the PRD (libraries, database schemas, frameworks, tech stacks, etc.) while filling in any gaps where the PRD isn't fully specified. Tasks are designed to provide the most direct implementation path while avoiding over-engineering.
|
* **Notes:** Task Master will strictly adhere to any specific requirements mentioned in the PRD (libraries, database schemas, frameworks, tech stacks, etc.) while filling in any gaps where the PRD isn't fully specified. Tasks are designed to provide the most direct implementation path while avoiding over-engineering.
|
||||||
* **Important:** This MCP tool makes AI calls and can take up to a minute to complete. Please inform users to hang tight while the operation is in progress.
|
* **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.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ globs: "**/*.test.js,tests/**/*"
|
|||||||
|
|
||||||
# Testing Guidelines for Task Master CLI
|
# Testing Guidelines for Task Master CLI
|
||||||
|
|
||||||
|
*Note:* Never use asynchronous operations in tests. Always mock tests properly based on the way the tested functions are defined and used. Do not arbitrarily create tests. Based them on the low-level details and execution of the underlying code being tested.
|
||||||
|
|
||||||
## Test Organization Structure
|
## Test Organization Structure
|
||||||
|
|
||||||
- **Unit Tests** (See [`architecture.mdc`](mdc:.cursor/rules/architecture.mdc) for module breakdown)
|
- **Unit Tests** (See [`architecture.mdc`](mdc:.cursor/rules/architecture.mdc) for module breakdown)
|
||||||
@@ -88,6 +90,122 @@ describe('Feature or Function Name', () => {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Commander.js Command Testing Best Practices
|
||||||
|
|
||||||
|
When testing CLI commands built with Commander.js, several special considerations must be made to avoid common pitfalls:
|
||||||
|
|
||||||
|
- **Direct Action Handler Testing**
|
||||||
|
- ✅ **DO**: Test the command action handlers directly rather than trying to mock the entire Commander.js chain
|
||||||
|
- ✅ **DO**: Create simplified test-specific implementations of command handlers that match the original behavior
|
||||||
|
- ✅ **DO**: Explicitly handle all options, including defaults and shorthand flags (e.g., `-p` for `--prompt`)
|
||||||
|
- ✅ **DO**: Include null/undefined checks in test implementations for parameters that might be optional
|
||||||
|
- ✅ **DO**: Use fixtures from `tests/fixtures/` for consistent sample data across tests
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// ✅ DO: Create a simplified test version of the command handler
|
||||||
|
const testAddTaskAction = async (options) => {
|
||||||
|
options = options || {}; // Ensure options aren't undefined
|
||||||
|
|
||||||
|
// Validate parameters
|
||||||
|
const isManualCreation = options.title && options.description;
|
||||||
|
const prompt = options.prompt || options.p; // Handle shorthand flags
|
||||||
|
|
||||||
|
if (!prompt && !isManualCreation) {
|
||||||
|
throw new Error('Expected error message');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call the mocked task manager
|
||||||
|
return mockTaskManager.addTask(/* parameters */);
|
||||||
|
};
|
||||||
|
|
||||||
|
test('should handle required parameters correctly', async () => {
|
||||||
|
// Call the test implementation directly
|
||||||
|
await expect(async () => {
|
||||||
|
await testAddTaskAction({ file: 'tasks.json' });
|
||||||
|
}).rejects.toThrow('Expected error message');
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Commander Chain Mocking (If Necessary)**
|
||||||
|
- ✅ **DO**: Mock ALL chainable methods (`option`, `argument`, `action`, `on`, etc.)
|
||||||
|
- ✅ **DO**: Return `this` (or the mock object) from all chainable method mocks
|
||||||
|
- ✅ **DO**: Remember to mock not only the initial object but also all objects returned by methods
|
||||||
|
- ✅ **DO**: Implement a mechanism to capture the action handler for direct testing
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// If you must mock the Commander.js chain:
|
||||||
|
const mockCommand = {
|
||||||
|
command: jest.fn().mockReturnThis(),
|
||||||
|
description: jest.fn().mockReturnThis(),
|
||||||
|
option: jest.fn().mockReturnThis(),
|
||||||
|
argument: jest.fn().mockReturnThis(), // Don't forget this one
|
||||||
|
action: jest.fn(fn => {
|
||||||
|
actionHandler = fn; // Capture the handler for testing
|
||||||
|
return mockCommand;
|
||||||
|
}),
|
||||||
|
on: jest.fn().mockReturnThis() // Don't forget this one
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameter Handling**
|
||||||
|
- ✅ **DO**: Check for both main flag and shorthand flags (e.g., `prompt` and `p`)
|
||||||
|
- ✅ **DO**: Handle parameters like Commander would (comma-separated lists, etc.)
|
||||||
|
- ✅ **DO**: Set proper default values as defined in the command
|
||||||
|
- ✅ **DO**: Validate that required parameters are actually required in tests
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Parse dependencies like Commander would
|
||||||
|
const dependencies = options.dependencies
|
||||||
|
? options.dependencies.split(',').map(id => id.trim())
|
||||||
|
: [];
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Environment and Session Handling**
|
||||||
|
- ✅ **DO**: Properly mock session objects when required by functions
|
||||||
|
- ✅ **DO**: Reset environment variables between tests if modified
|
||||||
|
- ✅ **DO**: Use a consistent pattern for environment-dependent tests
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Session parameter mock pattern
|
||||||
|
const sessionMock = { session: process.env };
|
||||||
|
|
||||||
|
// In test:
|
||||||
|
expect(mockAddTask).toHaveBeenCalledWith(
|
||||||
|
expect.any(String),
|
||||||
|
'Test prompt',
|
||||||
|
[],
|
||||||
|
'medium',
|
||||||
|
sessionMock,
|
||||||
|
false,
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Common Pitfalls to Avoid**
|
||||||
|
- ❌ **DON'T**: Try to use the real action implementation without proper mocking
|
||||||
|
- ❌ **DON'T**: Mock Commander partially - either mock it completely or test the action directly
|
||||||
|
- ❌ **DON'T**: Forget to handle optional parameters that may be undefined
|
||||||
|
- ❌ **DON'T**: Neglect to test shorthand flag functionality (e.g., `-p`, `-r`)
|
||||||
|
- ❌ **DON'T**: Create circular dependencies in your test mocks
|
||||||
|
- ❌ **DON'T**: Access variables before initialization in your test implementations
|
||||||
|
- ❌ **DON'T**: Include actual command execution in unit tests
|
||||||
|
- ❌ **DON'T**: Overwrite the same file path in multiple tests
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// ❌ DON'T: Create circular references in mocks
|
||||||
|
const badMock = {
|
||||||
|
method: jest.fn().mockImplementation(() => badMock.method())
|
||||||
|
};
|
||||||
|
|
||||||
|
// ❌ DON'T: Access uninitialized variables
|
||||||
|
const badImplementation = () => {
|
||||||
|
const result = uninitialized;
|
||||||
|
let uninitialized = 'value';
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
## Jest Module Mocking Best Practices
|
## Jest Module Mocking Best Practices
|
||||||
|
|
||||||
- **Mock Hoisting Behavior**
|
- **Mock Hoisting Behavior**
|
||||||
@@ -552,6 +670,102 @@ npm test -- -t "pattern to match"
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Testing AI Service Integrations
|
||||||
|
|
||||||
|
- **DO NOT import real AI service clients**
|
||||||
|
- ❌ DON'T: Import actual AI clients from their libraries
|
||||||
|
- ✅ DO: Create fully mocked versions that return predictable responses
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// ❌ DON'T: Import and instantiate real AI clients
|
||||||
|
import { Anthropic } from '@anthropic-ai/sdk';
|
||||||
|
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
|
||||||
|
|
||||||
|
// ✅ DO: Mock the entire module with controlled behavior
|
||||||
|
jest.mock('@anthropic-ai/sdk', () => ({
|
||||||
|
Anthropic: jest.fn().mockImplementation(() => ({
|
||||||
|
messages: {
|
||||||
|
create: jest.fn().mockResolvedValue({
|
||||||
|
content: [{ type: 'text', text: 'Mocked AI response' }]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}));
|
||||||
|
```
|
||||||
|
|
||||||
|
- **DO NOT rely on environment variables for API keys**
|
||||||
|
- ❌ DON'T: Assume environment variables are set in tests
|
||||||
|
- ✅ DO: Set mock environment variables in test setup
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// In tests/setup.js or at the top of test file
|
||||||
|
process.env.ANTHROPIC_API_KEY = 'test-mock-api-key-for-tests';
|
||||||
|
process.env.PERPLEXITY_API_KEY = 'test-mock-perplexity-key-for-tests';
|
||||||
|
```
|
||||||
|
|
||||||
|
- **DO NOT use real AI client initialization logic**
|
||||||
|
- ❌ DON'T: Use code that attempts to initialize or validate real AI clients
|
||||||
|
- ✅ DO: Create test-specific paths that bypass client initialization
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// ❌ DON'T: Test functions that require valid AI client initialization
|
||||||
|
// This will fail without proper API keys or network access
|
||||||
|
test('should use AI client', async () => {
|
||||||
|
const result = await functionThatInitializesAIClient();
|
||||||
|
expect(result).toBeDefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
// ✅ DO: Test with bypassed initialization or manual task paths
|
||||||
|
test('should handle manual task creation without AI', () => {
|
||||||
|
// Using a path that doesn't require AI client initialization
|
||||||
|
const result = addTaskDirect({
|
||||||
|
title: 'Manual Task',
|
||||||
|
description: 'Test Description'
|
||||||
|
}, mockLogger);
|
||||||
|
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Testing Asynchronous Code
|
||||||
|
|
||||||
|
- **DO NOT rely on asynchronous operations in tests**
|
||||||
|
- ❌ DON'T: Use real async/await or Promise resolution in tests
|
||||||
|
- ✅ DO: Make all mocks return synchronous values when possible
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// ❌ DON'T: Use real async functions that might fail unpredictably
|
||||||
|
test('should handle async operation', async () => {
|
||||||
|
const result = await realAsyncFunction(); // Can time out or fail for external reasons
|
||||||
|
expect(result).toBe(expectedValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ✅ DO: Make async operations synchronous in tests
|
||||||
|
test('should handle operation', () => {
|
||||||
|
mockAsyncFunction.mockReturnValue({ success: true, data: 'test' });
|
||||||
|
const result = functionUnderTest();
|
||||||
|
expect(result).toEqual({ success: true, data: 'test' });
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
- **DO NOT test exact error messages**
|
||||||
|
- ❌ DON'T: Assert on exact error message text that might change
|
||||||
|
- ✅ DO: Test for error presence and general properties
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// ❌ DON'T: Test for exact error message text
|
||||||
|
expect(result.error).toBe('Could not connect to API: Network error');
|
||||||
|
|
||||||
|
// ✅ DO: Test for general error properties or message patterns
|
||||||
|
expect(result.success).toBe(false);
|
||||||
|
expect(result.error).toContain('Could not connect');
|
||||||
|
// Or even better:
|
||||||
|
expect(result).toMatchObject({
|
||||||
|
success: false,
|
||||||
|
error: expect.stringContaining('connect')
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## Reliable Testing Techniques
|
## Reliable Testing Techniques
|
||||||
|
|
||||||
- **Create Simplified Test Functions**
|
- **Create Simplified Test Functions**
|
||||||
@@ -564,99 +778,125 @@ npm test -- -t "pattern to match"
|
|||||||
const setTaskStatus = async (taskId, newStatus) => {
|
const setTaskStatus = async (taskId, newStatus) => {
|
||||||
const tasksPath = 'tasks/tasks.json';
|
const tasksPath = 'tasks/tasks.json';
|
||||||
const data = await readJSON(tasksPath);
|
const data = await readJSON(tasksPath);
|
||||||
// Update task status logic
|
// [implementation]
|
||||||
await writeJSON(tasksPath, data);
|
await writeJSON(tasksPath, data);
|
||||||
return data;
|
return { success: true };
|
||||||
};
|
};
|
||||||
|
|
||||||
// Test-friendly simplified function (easy to test)
|
// Test-friendly version (easier to test)
|
||||||
const testSetTaskStatus = (tasksData, taskIdInput, newStatus) => {
|
const updateTaskStatus = (tasks, taskId, newStatus) => {
|
||||||
// Same core logic without file operations
|
// Pure logic without side effects
|
||||||
// Update task status logic on provided tasksData object
|
const updatedTasks = [...tasks];
|
||||||
return tasksData; // Return updated data for assertions
|
const taskIndex = findTaskById(updatedTasks, taskId);
|
||||||
|
if (taskIndex === -1) return { success: false, error: 'Task not found' };
|
||||||
|
updatedTasks[taskIndex].status = newStatus;
|
||||||
|
return { success: true, tasks: updatedTasks };
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
- **Avoid Real File System Operations**
|
|
||||||
- Never write to real files during tests
|
|
||||||
- Create test-specific versions of file operation functions
|
|
||||||
- Mock all file system operations including read, write, exists, etc.
|
|
||||||
- Verify function behavior using the in-memory data structures
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// Mock file operations
|
|
||||||
const mockReadJSON = jest.fn();
|
|
||||||
const mockWriteJSON = jest.fn();
|
|
||||||
|
|
||||||
jest.mock('../../scripts/modules/utils.js', () => ({
|
|
||||||
readJSON: mockReadJSON,
|
|
||||||
writeJSON: mockWriteJSON,
|
|
||||||
}));
|
|
||||||
|
|
||||||
test('should update task status correctly', () => {
|
|
||||||
// Setup mock data
|
|
||||||
const testData = JSON.parse(JSON.stringify(sampleTasks));
|
|
||||||
mockReadJSON.mockReturnValue(testData);
|
|
||||||
|
|
||||||
// Call the function that would normally modify files
|
|
||||||
const result = testSetTaskStatus(testData, '1', 'done');
|
|
||||||
|
|
||||||
// Assert on the in-memory data structure
|
|
||||||
expect(result.tasks[0].status).toBe('done');
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Data Isolation Between Tests**
|
|
||||||
- Always create fresh copies of test data for each test
|
|
||||||
- Use `JSON.parse(JSON.stringify(original))` for deep cloning
|
|
||||||
- Reset all mocks before each test with `jest.clearAllMocks()`
|
|
||||||
- Avoid state that persists between tests
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
beforeEach(() => {
|
|
||||||
jest.clearAllMocks();
|
|
||||||
// Deep clone the test data
|
|
||||||
testTasksData = JSON.parse(JSON.stringify(sampleTasks));
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Test All Path Variations**
|
|
||||||
- Regular tasks and subtasks
|
|
||||||
- Single items and multiple items
|
|
||||||
- Success paths and error paths
|
|
||||||
- Edge cases (empty data, invalid inputs, etc.)
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// Multiple test cases covering different scenarios
|
|
||||||
test('should update regular task status', () => {
|
|
||||||
/* test implementation */
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should update subtask status', () => {
|
|
||||||
/* test implementation */
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should update multiple tasks when given comma-separated IDs', () => {
|
|
||||||
/* test implementation */
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should throw error for non-existent task ID', () => {
|
|
||||||
/* test implementation */
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Stabilize Tests With Predictable Input/Output**
|
|
||||||
- Use consistent, predictable test fixtures
|
|
||||||
- Avoid random values or time-dependent data
|
|
||||||
- Make tests deterministic for reliable CI/CD
|
|
||||||
- Control all variables that might affect test outcomes
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// Use a specific known date instead of current date
|
|
||||||
const fixedDate = new Date('2023-01-01T12:00:00Z');
|
|
||||||
jest.spyOn(global, 'Date').mockImplementation(() => fixedDate);
|
|
||||||
```
|
|
||||||
|
|
||||||
See [tests/README.md](mdc:tests/README.md) for more details on the testing approach.
|
See [tests/README.md](mdc:tests/README.md) for more details on the testing approach.
|
||||||
|
|
||||||
Refer to [jest.config.js](mdc:jest.config.js) for Jest configuration options.
|
Refer to [jest.config.js](mdc:jest.config.js) for Jest configuration options.
|
||||||
|
|
||||||
|
## Variable Hoisting and Module Initialization Issues
|
||||||
|
|
||||||
|
When testing ES modules or working with complex module imports, you may encounter variable hoisting and initialization issues. These can be particularly tricky to debug and often appear as "Cannot access 'X' before initialization" errors.
|
||||||
|
|
||||||
|
- **Understanding Module Initialization Order**
|
||||||
|
- ✅ **DO**: Declare and initialize global variables at the top of modules
|
||||||
|
- ✅ **DO**: Use proper function declarations to avoid hoisting issues
|
||||||
|
- ✅ **DO**: Initialize variables before they are referenced, especially in imported modules
|
||||||
|
- ✅ **DO**: Be aware that imports are hoisted to the top of the file
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// ✅ DO: Define global state variables at the top of the module
|
||||||
|
let silentMode = false; // Declare and initialize first
|
||||||
|
|
||||||
|
const CONFIG = { /* configuration */ };
|
||||||
|
|
||||||
|
function isSilentMode() {
|
||||||
|
return silentMode; // Reference variable after it's initialized
|
||||||
|
}
|
||||||
|
|
||||||
|
function log(level, message) {
|
||||||
|
if (isSilentMode()) return; // Use the function instead of accessing variable directly
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Testing Modules with Initialization-Dependent Functions**
|
||||||
|
- ✅ **DO**: Create test-specific implementations that initialize all variables correctly
|
||||||
|
- ✅ **DO**: Use factory functions in mocks to ensure proper initialization order
|
||||||
|
- ✅ **DO**: Be careful with how you mock or stub functions that depend on module state
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// ✅ DO: Test-specific implementation that avoids initialization issues
|
||||||
|
const testLog = (level, ...args) => {
|
||||||
|
// Local implementation with proper initialization
|
||||||
|
const isSilent = false; // Explicit initialization
|
||||||
|
if (isSilent) return;
|
||||||
|
// Test implementation...
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Common Hoisting-Related Errors to Avoid**
|
||||||
|
- ❌ **DON'T**: Reference variables before their declaration in module scope
|
||||||
|
- ❌ **DON'T**: Create circular dependencies between modules
|
||||||
|
- ❌ **DON'T**: Rely on variable initialization order across module boundaries
|
||||||
|
- ❌ **DON'T**: Define functions that use hoisted variables before they're initialized
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// ❌ DON'T: Create reference-before-initialization patterns
|
||||||
|
function badFunction() {
|
||||||
|
if (silentMode) { /* ... */ } // ReferenceError if silentMode is declared later
|
||||||
|
}
|
||||||
|
|
||||||
|
let silentMode = false;
|
||||||
|
|
||||||
|
// ❌ DON'T: Create cross-module references that depend on initialization order
|
||||||
|
// module-a.js
|
||||||
|
import { getSetting } from './module-b.js';
|
||||||
|
export const config = { value: getSetting() };
|
||||||
|
|
||||||
|
// module-b.js
|
||||||
|
import { config } from './module-a.js';
|
||||||
|
export function getSetting() {
|
||||||
|
return config.value; // Circular dependency causing initialization issues
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Dynamic Imports as a Solution**
|
||||||
|
- ✅ **DO**: Use dynamic imports (`import()`) to avoid initialization order issues
|
||||||
|
- ✅ **DO**: Structure modules to avoid circular dependencies that cause initialization issues
|
||||||
|
- ✅ **DO**: Consider factory functions for modules with complex state
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// ✅ DO: Use dynamic imports to avoid initialization issues
|
||||||
|
async function getTaskManager() {
|
||||||
|
return import('./task-manager.js');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function someFunction() {
|
||||||
|
const taskManager = await getTaskManager();
|
||||||
|
return taskManager.someMethod();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Testing Approach for Modules with Initialization Issues**
|
||||||
|
- ✅ **DO**: Create self-contained test implementations rather than using real implementations
|
||||||
|
- ✅ **DO**: Mock dependencies at module boundaries instead of trying to mock deep dependencies
|
||||||
|
- ✅ **DO**: Isolate module-specific state in tests
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// ✅ DO: Create isolated test implementation instead of reusing module code
|
||||||
|
test('should log messages when not in silent mode', () => {
|
||||||
|
// Local test implementation instead of importing from module
|
||||||
|
const testLog = (level, message) => {
|
||||||
|
if (false) return; // Always non-silent for this test
|
||||||
|
mockConsole(level, message);
|
||||||
|
};
|
||||||
|
|
||||||
|
testLog('info', 'test message');
|
||||||
|
expect(mockConsole).toHaveBeenCalledWith('info', 'test message');
|
||||||
|
});
|
||||||
|
```
|
||||||
39
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
39
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
---
|
||||||
|
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.
|
||||||
51
.github/ISSUE_TEMPLATE/enhancements---feature-requests.md
vendored
Normal file
51
.github/ISSUE_TEMPLATE/enhancements---feature-requests.md
vendored
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
---
|
||||||
|
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
Normal file
31
.github/ISSUE_TEMPLATE/feedback.md
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
---
|
||||||
|
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
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
setup:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -24,21 +24,55 @@ jobs:
|
|||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 20
|
||||||
cache: "npm"
|
cache: 'npm'
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
id: install
|
||||||
|
run: npm ci
|
||||||
|
timeout-minutes: 2
|
||||||
|
|
||||||
- name: Cache node_modules
|
- name: Cache node_modules
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: |
|
path: node_modules
|
||||||
node_modules
|
key: ${{ runner.os }}-node-modules-${{ hashFiles('**/package-lock.json') }}
|
||||||
*/*/node_modules
|
|
||||||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
|
||||||
restore-keys: |
|
|
||||||
${{ runner.os }}-node-
|
|
||||||
|
|
||||||
- name: Install Dependencies
|
format-check:
|
||||||
run: npm ci
|
needs: setup
|
||||||
timeout-minutes: 2
|
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: Run Tests
|
- name: Run Tests
|
||||||
run: |
|
run: |
|
||||||
@@ -47,13 +81,13 @@ jobs:
|
|||||||
NODE_ENV: test
|
NODE_ENV: test
|
||||||
CI: true
|
CI: true
|
||||||
FORCE_COLOR: 1
|
FORCE_COLOR: 1
|
||||||
timeout-minutes: 15
|
timeout-minutes: 10
|
||||||
|
|
||||||
- name: Upload Test Results
|
- name: Upload Test Results
|
||||||
if: always()
|
if: always()
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: test-results-node
|
name: test-results
|
||||||
path: |
|
path: |
|
||||||
test-results
|
test-results
|
||||||
coverage
|
coverage
|
||||||
|
|||||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
|||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: 20
|
||||||
cache: "npm"
|
cache: 'npm'
|
||||||
|
|
||||||
- name: Cache node_modules
|
- name: Cache node_modules
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
|
|||||||
6
.prettierignore
Normal file
6
.prettierignore
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# Ignore artifacts:
|
||||||
|
build
|
||||||
|
coverage
|
||||||
|
.changeset
|
||||||
|
tasks
|
||||||
|
package-lock.json
|
||||||
11
.prettierrc
Normal file
11
.prettierrc
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 80,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": true,
|
||||||
|
"semi": true,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "none",
|
||||||
|
"bracketSpacing": true,
|
||||||
|
"arrowParens": "always",
|
||||||
|
"endOfLine": "lf"
|
||||||
|
}
|
||||||
3
.vscode/extensions.json
vendored
Normal file
3
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"recommendations": ["esbenp.prettier-vscode"]
|
||||||
|
}
|
||||||
90
LICENSE.md
90
LICENSE.md
@@ -1,90 +0,0 @@
|
|||||||
# 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,6 +58,7 @@ This will prompt you for project details and set up a new project with the neces
|
|||||||
### Important Notes
|
### Important Notes
|
||||||
|
|
||||||
1. **ES Modules Configuration:**
|
1. **ES Modules Configuration:**
|
||||||
|
|
||||||
- This project uses ES Modules (ESM) instead of CommonJS.
|
- This project uses ES Modules (ESM) instead of CommonJS.
|
||||||
- This is set via `"type": "module"` in your package.json.
|
- This is set via `"type": "module"` in your package.json.
|
||||||
- Use `import/export` syntax instead of `require()`.
|
- Use `import/export` syntax instead of `require()`.
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -1,8 +1,6 @@
|
|||||||
# Task Master [](https://github.com/eyaltoledano/claude-task-master/stargazers)
|
# 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)
|
[](https://github.com/eyaltoledano/claude-task-master/actions/workflows/ci.yml) [](https://badge.fury.io/js/task-master-ai)  [](LICENSE)
|
||||||
|
|
||||||
 [](LICENSE)
|
|
||||||
|
|
||||||
### By [@eyaltoledano](https://x.com/eyaltoledano) & [@RalphEcom](https://x.com/RalphEcom)
|
### By [@eyaltoledano](https://x.com/eyaltoledano) & [@RalphEcom](https://x.com/RalphEcom)
|
||||||
|
|
||||||
@@ -29,7 +27,7 @@ MCP (Model Control Protocol) provides the easiest way to get started with Task M
|
|||||||
"mcpServers": {
|
"mcpServers": {
|
||||||
"taskmaster-ai": {
|
"taskmaster-ai": {
|
||||||
"command": "npx",
|
"command": "npx",
|
||||||
"args": ["-y", "task-master-ai", "mcp-server"],
|
"args": ["-y", "--package", "task-master-ai", "task-master-mcp"],
|
||||||
"env": {
|
"env": {
|
||||||
"ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE",
|
"ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE",
|
||||||
"PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE",
|
"PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE",
|
||||||
@@ -133,6 +131,12 @@ cd claude-task-master
|
|||||||
node scripts/init.js
|
node scripts/init.js
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
<a href="https://github.com/eyaltoledano/claude-task-master/graphs/contributors">
|
||||||
|
<img src="https://contrib.rocks/image?repo=eyaltoledano/claude-task-master" alt="Task Master project contributors" />
|
||||||
|
</a>
|
||||||
|
|
||||||
## Star History
|
## Star History
|
||||||
|
|
||||||
[](https://www.star-history.com/#eyaltoledano/claude-task-master&Timeline)
|
[](https://www.star-history.com/#eyaltoledano/claude-task-master&Timeline)
|
||||||
|
|||||||
@@ -21,9 +21,11 @@ In an AI-driven development process—particularly with tools like [Cursor](http
|
|||||||
The script can be configured through environment variables in a `.env` file at the root of the project:
|
The script can be configured through environment variables in a `.env` file at the root of the project:
|
||||||
|
|
||||||
### Required Configuration
|
### Required Configuration
|
||||||
|
|
||||||
- `ANTHROPIC_API_KEY`: Your Anthropic API key for Claude
|
- `ANTHROPIC_API_KEY`: Your Anthropic API key for Claude
|
||||||
|
|
||||||
### Optional Configuration
|
### Optional Configuration
|
||||||
|
|
||||||
- `MODEL`: Specify which Claude model to use (default: "claude-3-7-sonnet-20250219")
|
- `MODEL`: Specify which Claude model to use (default: "claude-3-7-sonnet-20250219")
|
||||||
- `MAX_TOKENS`: Maximum tokens for model responses (default: 4000)
|
- `MAX_TOKENS`: Maximum tokens for model responses (default: 4000)
|
||||||
- `TEMPERATURE`: Temperature for model responses (default: 0.7)
|
- `TEMPERATURE`: Temperature for model responses (default: 0.7)
|
||||||
@@ -39,6 +41,7 @@ The script can be configured through environment variables in a `.env` file at t
|
|||||||
## How It Works
|
## How It Works
|
||||||
|
|
||||||
1. **`tasks.json`**:
|
1. **`tasks.json`**:
|
||||||
|
|
||||||
- A JSON file at the project root containing an array of tasks (each with `id`, `title`, `description`, `status`, etc.).
|
- A JSON file at the project root containing an array of tasks (each with `id`, `title`, `description`, `status`, etc.).
|
||||||
- The `meta` field can store additional info like the project's name, version, or reference to the PRD.
|
- The `meta` field can store additional info like the project's name, version, or reference to the PRD.
|
||||||
- Tasks can have `subtasks` for more detailed implementation steps.
|
- Tasks can have `subtasks` for more detailed implementation steps.
|
||||||
@@ -111,6 +114,7 @@ task-master update --file=custom-tasks.json --from=5 --prompt="Change database f
|
|||||||
```
|
```
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
- The `--prompt` parameter is required and should explain the changes or new context
|
- The `--prompt` parameter is required and should explain the changes or new context
|
||||||
- Only tasks that aren't marked as 'done' will be updated
|
- Only tasks that aren't marked as 'done' will be updated
|
||||||
- Tasks with ID >= the specified --from value will be updated
|
- Tasks with ID >= the specified --from value will be updated
|
||||||
@@ -134,6 +138,7 @@ task-master set-status --id=1,2,3 --status=done
|
|||||||
```
|
```
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
- When marking a parent task as "done", all of its subtasks will automatically be marked as "done" as well
|
- When marking a parent task as "done", all of its subtasks will automatically be marked as "done" as well
|
||||||
- Common status values are 'done', 'pending', and 'deferred', but any string is accepted
|
- Common status values are 'done', 'pending', and 'deferred', but any string is accepted
|
||||||
- You can specify multiple task IDs by separating them with commas
|
- You can specify multiple task IDs by separating them with commas
|
||||||
@@ -183,6 +188,7 @@ task-master clear-subtasks --all
|
|||||||
```
|
```
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
- After clearing subtasks, task files are automatically regenerated
|
- After clearing subtasks, task files are automatically regenerated
|
||||||
- This is useful when you want to regenerate subtasks with a different approach
|
- This is useful when you want to regenerate subtasks with a different approach
|
||||||
- Can be combined with the `expand` command to immediately generate new subtasks
|
- Can be combined with the `expand` command to immediately generate new subtasks
|
||||||
@@ -198,6 +204,7 @@ The script integrates with two AI services:
|
|||||||
The Perplexity integration uses the OpenAI client to connect to Perplexity's API, which provides enhanced research capabilities for generating more informed subtasks. If the Perplexity API is unavailable or encounters an error, the script will automatically fall back to using Anthropic's Claude.
|
The Perplexity integration uses the OpenAI client to connect to Perplexity's API, which provides enhanced research capabilities for generating more informed subtasks. If the Perplexity API is unavailable or encounters an error, the script will automatically fall back to using Anthropic's Claude.
|
||||||
|
|
||||||
To use the Perplexity integration:
|
To use the Perplexity integration:
|
||||||
|
|
||||||
1. Obtain a Perplexity API key
|
1. Obtain a Perplexity API key
|
||||||
2. Add `PERPLEXITY_API_KEY` to your `.env` file
|
2. Add `PERPLEXITY_API_KEY` to your `.env` file
|
||||||
3. Optionally specify `PERPLEXITY_MODEL` in your `.env` file (default: "sonar-medium-online")
|
3. Optionally specify `PERPLEXITY_MODEL` in your `.env` file (default: "sonar-medium-online")
|
||||||
@@ -206,6 +213,7 @@ To use the Perplexity integration:
|
|||||||
## Logging
|
## Logging
|
||||||
|
|
||||||
The script supports different logging levels controlled by the `LOG_LEVEL` environment variable:
|
The script supports different logging levels controlled by the `LOG_LEVEL` environment variable:
|
||||||
|
|
||||||
- `debug`: Detailed information, typically useful for troubleshooting
|
- `debug`: Detailed information, typically useful for troubleshooting
|
||||||
- `info`: Confirmation that things are working as expected (default)
|
- `info`: Confirmation that things are working as expected (default)
|
||||||
- `warn`: Warning messages that don't prevent execution
|
- `warn`: Warning messages that don't prevent execution
|
||||||
@@ -228,17 +236,20 @@ task-master remove-dependency --id=<id> --depends-on=<id>
|
|||||||
These commands:
|
These commands:
|
||||||
|
|
||||||
1. **Allow precise dependency management**:
|
1. **Allow precise dependency management**:
|
||||||
|
|
||||||
- Add dependencies between tasks with automatic validation
|
- Add dependencies between tasks with automatic validation
|
||||||
- Remove dependencies when they're no longer needed
|
- Remove dependencies when they're no longer needed
|
||||||
- Update task files automatically after changes
|
- Update task files automatically after changes
|
||||||
|
|
||||||
2. **Include validation checks**:
|
2. **Include validation checks**:
|
||||||
|
|
||||||
- Prevent circular dependencies (a task depending on itself)
|
- Prevent circular dependencies (a task depending on itself)
|
||||||
- Prevent duplicate dependencies
|
- Prevent duplicate dependencies
|
||||||
- Verify that both tasks exist before adding/removing dependencies
|
- Verify that both tasks exist before adding/removing dependencies
|
||||||
- Check if dependencies exist before attempting to remove them
|
- Check if dependencies exist before attempting to remove them
|
||||||
|
|
||||||
3. **Provide clear feedback**:
|
3. **Provide clear feedback**:
|
||||||
|
|
||||||
- Success messages confirm when dependencies are added/removed
|
- Success messages confirm when dependencies are added/removed
|
||||||
- Error messages explain why operations failed (if applicable)
|
- Error messages explain why operations failed (if applicable)
|
||||||
|
|
||||||
@@ -263,6 +274,7 @@ task-master validate-dependencies --file=custom-tasks.json
|
|||||||
```
|
```
|
||||||
|
|
||||||
This command:
|
This command:
|
||||||
|
|
||||||
- Scans all tasks and subtasks for non-existent dependencies
|
- Scans all tasks and subtasks for non-existent dependencies
|
||||||
- Identifies potential self-dependencies (tasks referencing themselves)
|
- Identifies potential self-dependencies (tasks referencing themselves)
|
||||||
- Reports all found issues without modifying files
|
- Reports all found issues without modifying files
|
||||||
@@ -284,6 +296,7 @@ task-master fix-dependencies --file=custom-tasks.json
|
|||||||
```
|
```
|
||||||
|
|
||||||
This command:
|
This command:
|
||||||
|
|
||||||
1. **Validates all dependencies** across tasks and subtasks
|
1. **Validates all dependencies** across tasks and subtasks
|
||||||
2. **Automatically removes**:
|
2. **Automatically removes**:
|
||||||
- References to non-existent tasks and subtasks
|
- References to non-existent tasks and subtasks
|
||||||
@@ -321,6 +334,7 @@ task-master analyze-complexity --research
|
|||||||
```
|
```
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
- The command uses Claude to analyze each task's complexity (or Perplexity with --research flag)
|
- The command uses Claude to analyze each task's complexity (or Perplexity with --research flag)
|
||||||
- Tasks are scored on a scale of 1-10
|
- Tasks are scored on a scale of 1-10
|
||||||
- Each task receives a recommended number of subtasks based on DEFAULT_SUBTASKS configuration
|
- Each task receives a recommended number of subtasks based on DEFAULT_SUBTASKS configuration
|
||||||
@@ -345,12 +359,14 @@ task-master expand --id=8 --num=5 --prompt="Custom prompt"
|
|||||||
```
|
```
|
||||||
|
|
||||||
When a complexity report exists:
|
When a complexity report exists:
|
||||||
|
|
||||||
- The `expand` command will use the recommended subtask count from the report (unless overridden)
|
- The `expand` command will use the recommended subtask count from the report (unless overridden)
|
||||||
- It will use the tailored expansion prompt from the report (unless a custom prompt is provided)
|
- It will use the tailored expansion prompt from the report (unless a custom prompt is provided)
|
||||||
- When using `--all`, tasks are sorted by complexity score (highest first)
|
- When using `--all`, tasks are sorted by complexity score (highest first)
|
||||||
- The `--research` flag is preserved from the complexity analysis to expansion
|
- The `--research` flag is preserved from the complexity analysis to expansion
|
||||||
|
|
||||||
The output report structure is:
|
The output report structure is:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"meta": {
|
"meta": {
|
||||||
@@ -369,7 +385,7 @@ The output report structure is:
|
|||||||
"expansionPrompt": "Create subtasks that handle detecting...",
|
"expansionPrompt": "Create subtasks that handle detecting...",
|
||||||
"reasoning": "This task requires sophisticated logic...",
|
"reasoning": "This task requires sophisticated logic...",
|
||||||
"expansionCommand": "task-master expand --id=8 --num=6 --prompt=\"Create subtasks...\" --research"
|
"expansionCommand": "task-master expand --id=8 --num=6 --prompt=\"Create subtasks...\" --research"
|
||||||
},
|
}
|
||||||
// More tasks sorted by complexity score (highest first)
|
// More tasks sorted by complexity score (highest first)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
#!/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);
|
|
||||||
});
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node --trace-deprecation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task Master
|
* Task Master
|
||||||
@@ -49,7 +49,13 @@ function runDevScript(args) {
|
|||||||
console.error('\nDEBUG - CLI Wrapper Analysis:');
|
console.error('\nDEBUG - CLI Wrapper Analysis:');
|
||||||
console.error('- Original command: ' + process.argv.join(' '));
|
console.error('- Original command: ' + process.argv.join(' '));
|
||||||
console.error('- Transformed args: ' + args.join(' '));
|
console.error('- Transformed args: ' + args.join(' '));
|
||||||
console.error('- 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
|
// For testing: If TEST_MODE is set, just print args and exit
|
||||||
@@ -86,11 +92,13 @@ function createDevScriptAction(commandName) {
|
|||||||
// If camelCase flags were found, show error and exit
|
// If camelCase flags were found, show error and exit
|
||||||
if (camelCaseFlags.length > 0) {
|
if (camelCaseFlags.length > 0) {
|
||||||
console.error('\nError: Please use kebab-case for CLI flags:');
|
console.error('\nError: Please use kebab-case for CLI flags:');
|
||||||
camelCaseFlags.forEach(flag => {
|
camelCaseFlags.forEach((flag) => {
|
||||||
console.error(` Instead of: --${flag.original}`);
|
console.error(` Instead of: --${flag.original}`);
|
||||||
console.error(` Use: --${flag.kebabCase}`);
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,9 +121,11 @@ function createDevScriptAction(commandName) {
|
|||||||
// It's a flag - pass through as is
|
// It's a flag - pass through as is
|
||||||
commandArgs.push(arg);
|
commandArgs.push(arg);
|
||||||
// Skip the next arg if this is a flag with a value (not --flag=value format)
|
// 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 &&
|
i + 1 < process.argv.length &&
|
||||||
!process.argv[i+1].startsWith('--')) {
|
!process.argv[i + 1].startsWith('--')
|
||||||
|
) {
|
||||||
commandArgs.push(process.argv[++i]);
|
commandArgs.push(process.argv[++i]);
|
||||||
}
|
}
|
||||||
} else if (!positionals.has(arg)) {
|
} else if (!positionals.has(arg)) {
|
||||||
@@ -143,7 +153,9 @@ function createDevScriptAction(commandName) {
|
|||||||
userOptions.add(kebabName);
|
userOptions.add(kebabName);
|
||||||
|
|
||||||
// Add the camelCase version as well
|
// 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);
|
userOptions.add(camelName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,7 +179,10 @@ function createDevScriptAction(commandName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Skip built-in Commander properties and options the user provided
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,39 +225,47 @@ function createDevScriptAction(commandName) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case for the 'init' command which uses a different script
|
// // Special case for the 'init' command which uses a different script
|
||||||
function registerInitCommand(program) {
|
// function registerInitCommand(program) {
|
||||||
program
|
// program
|
||||||
.command('init')
|
// .command('init')
|
||||||
.description('Initialize a new project')
|
// .description('Initialize a new project')
|
||||||
.option('-y, --yes', 'Skip prompts and use default values')
|
// .option('-y, --yes', 'Skip prompts and use default values')
|
||||||
.option('-n, --name <name>', 'Project name')
|
// .option('-n, --name <name>', 'Project name')
|
||||||
.option('-d, --description <description>', 'Project description')
|
// .option('-d, --description <description>', 'Project description')
|
||||||
.option('-v, --version <version>', 'Project version')
|
// .option('-v, --version <version>', 'Project version')
|
||||||
.option('-a, --author <author>', 'Author name')
|
// .option('-a, --author <author>', 'Author name')
|
||||||
.option('--skip-install', 'Skip installing dependencies')
|
// .option('--skip-install', 'Skip installing dependencies')
|
||||||
.option('--dry-run', 'Show what would be done without making changes')
|
// .option('--dry-run', 'Show what would be done without making changes')
|
||||||
.action((options) => {
|
// .action((options) => {
|
||||||
// Pass through any options to the init script
|
// // Pass through any options to the init script
|
||||||
const args = ['--yes', 'name', 'description', 'version', 'author', 'skip-install', 'dry-run']
|
// const args = [
|
||||||
.filter(opt => options[opt])
|
// '--yes',
|
||||||
.map(opt => {
|
// 'name',
|
||||||
if (opt === 'yes' || opt === 'skip-install' || opt === 'dry-run') {
|
// 'description',
|
||||||
return `--${opt}`;
|
// 'version',
|
||||||
}
|
// 'author',
|
||||||
return `--${opt}=${options[opt]}`;
|
// '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], {
|
// const child = spawn('node', [initScriptPath, ...args], {
|
||||||
stdio: 'inherit',
|
// stdio: 'inherit',
|
||||||
cwd: process.cwd()
|
// cwd: process.cwd()
|
||||||
});
|
// });
|
||||||
|
|
||||||
child.on('close', (code) => {
|
// child.on('close', (code) => {
|
||||||
process.exit(code);
|
// process.exit(code);
|
||||||
});
|
// });
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Set up the command-line interface
|
// Set up the command-line interface
|
||||||
const program = new Command();
|
const program = new Command();
|
||||||
@@ -263,8 +286,8 @@ program.on('--help', () => {
|
|||||||
displayHelp();
|
displayHelp();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add special case commands
|
// // Add special case commands
|
||||||
registerInitCommand(program);
|
// registerInitCommand(program);
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('dev')
|
.command('dev')
|
||||||
@@ -279,24 +302,18 @@ const tempProgram = new Command();
|
|||||||
registerCommands(tempProgram);
|
registerCommands(tempProgram);
|
||||||
|
|
||||||
// For each command in the temp instance, add a modified version to our actual program
|
// For each command in the temp instance, add a modified version to our actual program
|
||||||
tempProgram.commands.forEach(cmd => {
|
tempProgram.commands.forEach((cmd) => {
|
||||||
if (['init', 'dev'].includes(cmd.name())) {
|
if (['dev'].includes(cmd.name())) {
|
||||||
// Skip commands we've already defined specially
|
// Skip commands we've already defined specially
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new command with the same name and description
|
// Create a new command with the same name and description
|
||||||
const newCmd = program
|
const newCmd = program.command(cmd.name()).description(cmd.description());
|
||||||
.command(cmd.name())
|
|
||||||
.description(cmd.description());
|
|
||||||
|
|
||||||
// Copy all options
|
// Copy all options
|
||||||
cmd.options.forEach(opt => {
|
cmd.options.forEach((opt) => {
|
||||||
newCmd.option(
|
newCmd.option(opt.flags, opt.description, opt.defaultValue);
|
||||||
opt.flags,
|
|
||||||
opt.description,
|
|
||||||
opt.defaultValue
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set the action to proxy to dev.js
|
// Set the action to proxy to dev.js
|
||||||
@@ -311,14 +328,21 @@ process.on('uncaughtException', (err) => {
|
|||||||
// Check if this is a commander.js unknown option error
|
// Check if this is a commander.js unknown option error
|
||||||
if (err.code === 'commander.unknownOption') {
|
if (err.code === 'commander.unknownOption') {
|
||||||
const option = err.message.match(/'([^']+)'/)?.[1];
|
const option = err.message.match(/'([^']+)'/)?.[1];
|
||||||
const commandArg = process.argv.find(arg => !arg.startsWith('-') &&
|
const commandArg = process.argv.find(
|
||||||
|
(arg) =>
|
||||||
|
!arg.startsWith('-') &&
|
||||||
arg !== 'task-master' &&
|
arg !== 'task-master' &&
|
||||||
!arg.includes('/') &&
|
!arg.includes('/') &&
|
||||||
arg !== 'node');
|
arg !== 'node'
|
||||||
|
);
|
||||||
const command = commandArg || 'unknown';
|
const command = commandArg || 'unknown';
|
||||||
|
|
||||||
console.error(chalk.red(`Error: Unknown option '${option}'`));
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,7 +351,9 @@ process.on('uncaughtException', (err) => {
|
|||||||
const command = err.message.match(/'([^']+)'/)?.[1];
|
const command = err.message.match(/'([^']+)'/)?.[1];
|
||||||
|
|
||||||
console.error(chalk.red(`Error: Unknown command '${command}'`));
|
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);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -186,22 +186,22 @@ const commandMap = {
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In mcp-server/src/tools/newFeature.js
|
// In mcp-server/src/tools/newFeature.js
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
executeTaskMasterCommand,
|
executeTaskMasterCommand,
|
||||||
createContentResponse,
|
createContentResponse,
|
||||||
createErrorResponse,
|
createErrorResponse
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
|
|
||||||
export function registerNewFeatureTool(server) {
|
export function registerNewFeatureTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "newFeature",
|
name: 'newFeature',
|
||||||
description: "Run the new feature",
|
description: 'Run the new feature',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
param1: z.string().describe("First parameter"),
|
param1: z.string().describe('First parameter'),
|
||||||
param2: z.number().optional().describe("Second parameter"),
|
param2: z.number().optional().describe('Second parameter'),
|
||||||
file: z.string().optional().describe("Path to the tasks file"),
|
file: z.string().optional().describe('Path to the tasks file'),
|
||||||
projectRoot: z.string().describe("Root directory of the project")
|
projectRoot: z.string().describe('Root directory of the project')
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log }) => {
|
execute: async (args, { log }) => {
|
||||||
try {
|
try {
|
||||||
@@ -216,7 +216,7 @@ export function registerNewFeatureTool(server) {
|
|||||||
|
|
||||||
// Execute the command
|
// Execute the command
|
||||||
const result = await executeTaskMasterCommand(
|
const result = await executeTaskMasterCommand(
|
||||||
"new-feature",
|
'new-feature',
|
||||||
log,
|
log,
|
||||||
cmdArgs,
|
cmdArgs,
|
||||||
projectRoot
|
projectRoot
|
||||||
@@ -231,7 +231,7 @@ export function registerNewFeatureTool(server) {
|
|||||||
log.error(`Error in new feature: ${error.message}`);
|
log.error(`Error in new feature: ${error.message}`);
|
||||||
return createErrorResponse(`Error in new feature: ${error.message}`);
|
return createErrorResponse(`Error in new feature: ${error.message}`);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -240,7 +240,7 @@ export function registerNewFeatureTool(server) {
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In mcp-server/src/tools/index.js
|
// In mcp-server/src/tools/index.js
|
||||||
import { registerNewFeatureTool } from "./newFeature.js";
|
import { registerNewFeatureTool } from './newFeature.js';
|
||||||
|
|
||||||
export function registerTaskMasterTools(server) {
|
export function registerTaskMasterTools(server) {
|
||||||
// ... existing registrations
|
// ... existing registrations
|
||||||
|
|||||||
@@ -41,11 +41,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["data", "mimeType", "type"],
|
||||||
"data",
|
|
||||||
"mimeType",
|
|
||||||
"type"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"BlobResourceContents": {
|
"BlobResourceContents": {
|
||||||
@@ -65,10 +61,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["blob", "uri"],
|
||||||
"blob",
|
|
||||||
"uri"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"CallToolRequest": {
|
"CallToolRequest": {
|
||||||
@@ -88,16 +81,11 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["name"],
|
||||||
"name"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method", "params"],
|
||||||
"method",
|
|
||||||
"params"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"CallToolResult": {
|
"CallToolResult": {
|
||||||
@@ -132,9 +120,7 @@
|
|||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["content"],
|
||||||
"content"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"CancelledNotification": {
|
"CancelledNotification": {
|
||||||
@@ -155,16 +141,11 @@
|
|||||||
"description": "The ID of the request to cancel.\n\nThis MUST correspond to the ID of a request previously issued in the same direction."
|
"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": [
|
"required": ["requestId"],
|
||||||
"requestId"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method", "params"],
|
||||||
"method",
|
|
||||||
"params"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ClientCapabilities": {
|
"ClientCapabilities": {
|
||||||
@@ -288,10 +269,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["name", "value"],
|
||||||
"name",
|
|
||||||
"value"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ref": {
|
"ref": {
|
||||||
@@ -305,17 +283,11 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["argument", "ref"],
|
||||||
"argument",
|
|
||||||
"ref"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method", "params"],
|
||||||
"method",
|
|
||||||
"params"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"CompleteResult": {
|
"CompleteResult": {
|
||||||
@@ -344,15 +316,11 @@
|
|||||||
"type": "array"
|
"type": "array"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["values"],
|
||||||
"values"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["completion"],
|
||||||
"completion"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"CreateMessageRequest": {
|
"CreateMessageRequest": {
|
||||||
@@ -366,11 +334,7 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"includeContext": {
|
"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.",
|
"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": [
|
"enum": ["allServers", "none", "thisServer"],
|
||||||
"allServers",
|
|
||||||
"none",
|
|
||||||
"thisServer"
|
|
||||||
],
|
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"maxTokens": {
|
"maxTokens": {
|
||||||
@@ -407,17 +371,11 @@
|
|||||||
"type": "number"
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["maxTokens", "messages"],
|
||||||
"maxTokens",
|
|
||||||
"messages"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method", "params"],
|
||||||
"method",
|
|
||||||
"params"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"CreateMessageResult": {
|
"CreateMessageResult": {
|
||||||
@@ -453,11 +411,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["content", "model", "role"],
|
||||||
"content",
|
|
||||||
"model",
|
|
||||||
"role"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"Cursor": {
|
"Cursor": {
|
||||||
@@ -486,10 +440,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["resource", "type"],
|
||||||
"resource",
|
|
||||||
"type"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"EmptyResult": {
|
"EmptyResult": {
|
||||||
@@ -516,16 +467,11 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["name"],
|
||||||
"name"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method", "params"],
|
||||||
"method",
|
|
||||||
"params"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"GetPromptResult": {
|
"GetPromptResult": {
|
||||||
@@ -547,9 +493,7 @@
|
|||||||
"type": "array"
|
"type": "array"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["messages"],
|
||||||
"messages"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ImageContent": {
|
"ImageContent": {
|
||||||
@@ -573,11 +517,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["data", "mimeType", "type"],
|
||||||
"data",
|
|
||||||
"mimeType",
|
|
||||||
"type"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"Implementation": {
|
"Implementation": {
|
||||||
@@ -590,10 +530,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["name", "version"],
|
||||||
"name",
|
|
||||||
"version"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"InitializeRequest": {
|
"InitializeRequest": {
|
||||||
@@ -616,18 +553,11 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["capabilities", "clientInfo", "protocolVersion"],
|
||||||
"capabilities",
|
|
||||||
"clientInfo",
|
|
||||||
"protocolVersion"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method", "params"],
|
||||||
"method",
|
|
||||||
"params"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"InitializeResult": {
|
"InitializeResult": {
|
||||||
@@ -653,11 +583,7 @@
|
|||||||
"$ref": "#/definitions/Implementation"
|
"$ref": "#/definitions/Implementation"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["capabilities", "protocolVersion", "serverInfo"],
|
||||||
"capabilities",
|
|
||||||
"protocolVersion",
|
|
||||||
"serverInfo"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"InitializedNotification": {
|
"InitializedNotification": {
|
||||||
@@ -679,9 +605,7 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method"],
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"JSONRPCBatchRequest": {
|
"JSONRPCBatchRequest": {
|
||||||
@@ -729,10 +653,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["code", "message"],
|
||||||
"code",
|
|
||||||
"message"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"id": {
|
"id": {
|
||||||
@@ -743,11 +664,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["error", "id", "jsonrpc"],
|
||||||
"error",
|
|
||||||
"id",
|
|
||||||
"jsonrpc"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"JSONRPCMessage": {
|
"JSONRPCMessage": {
|
||||||
@@ -817,10 +734,7 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["jsonrpc", "method"],
|
||||||
"jsonrpc",
|
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"JSONRPCRequest": {
|
"JSONRPCRequest": {
|
||||||
@@ -852,11 +766,7 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["id", "jsonrpc", "method"],
|
||||||
"id",
|
|
||||||
"jsonrpc",
|
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"JSONRPCResponse": {
|
"JSONRPCResponse": {
|
||||||
@@ -873,11 +783,7 @@
|
|||||||
"$ref": "#/definitions/Result"
|
"$ref": "#/definitions/Result"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["id", "jsonrpc", "result"],
|
||||||
"id",
|
|
||||||
"jsonrpc",
|
|
||||||
"result"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ListPromptsRequest": {
|
"ListPromptsRequest": {
|
||||||
@@ -897,9 +803,7 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method"],
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ListPromptsResult": {
|
"ListPromptsResult": {
|
||||||
@@ -921,9 +825,7 @@
|
|||||||
"type": "array"
|
"type": "array"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["prompts"],
|
||||||
"prompts"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ListResourceTemplatesRequest": {
|
"ListResourceTemplatesRequest": {
|
||||||
@@ -943,9 +845,7 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method"],
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ListResourceTemplatesResult": {
|
"ListResourceTemplatesResult": {
|
||||||
@@ -967,9 +867,7 @@
|
|||||||
"type": "array"
|
"type": "array"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["resourceTemplates"],
|
||||||
"resourceTemplates"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ListResourcesRequest": {
|
"ListResourcesRequest": {
|
||||||
@@ -989,9 +887,7 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method"],
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ListResourcesResult": {
|
"ListResourcesResult": {
|
||||||
@@ -1013,9 +909,7 @@
|
|||||||
"type": "array"
|
"type": "array"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["resources"],
|
||||||
"resources"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ListRootsRequest": {
|
"ListRootsRequest": {
|
||||||
@@ -1041,9 +935,7 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method"],
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ListRootsResult": {
|
"ListRootsResult": {
|
||||||
@@ -1061,9 +953,7 @@
|
|||||||
"type": "array"
|
"type": "array"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["roots"],
|
||||||
"roots"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ListToolsRequest": {
|
"ListToolsRequest": {
|
||||||
@@ -1083,9 +973,7 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method"],
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ListToolsResult": {
|
"ListToolsResult": {
|
||||||
@@ -1107,9 +995,7 @@
|
|||||||
"type": "array"
|
"type": "array"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["tools"],
|
||||||
"tools"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"LoggingLevel": {
|
"LoggingLevel": {
|
||||||
@@ -1147,17 +1033,11 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["data", "level"],
|
||||||
"data",
|
|
||||||
"level"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method", "params"],
|
||||||
"method",
|
|
||||||
"params"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ModelHint": {
|
"ModelHint": {
|
||||||
@@ -1218,9 +1098,7 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method"],
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"PaginatedRequest": {
|
"PaginatedRequest": {
|
||||||
@@ -1238,9 +1116,7 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method"],
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"PaginatedResult": {
|
"PaginatedResult": {
|
||||||
@@ -1280,9 +1156,7 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method"],
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ProgressNotification": {
|
"ProgressNotification": {
|
||||||
@@ -1311,25 +1185,16 @@
|
|||||||
"type": "number"
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["progress", "progressToken"],
|
||||||
"progress",
|
|
||||||
"progressToken"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method", "params"],
|
||||||
"method",
|
|
||||||
"params"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ProgressToken": {
|
"ProgressToken": {
|
||||||
"description": "A progress token, used to associate progress notifications with the original request.",
|
"description": "A progress token, used to associate progress notifications with the original request.",
|
||||||
"type": [
|
"type": ["string", "integer"]
|
||||||
"string",
|
|
||||||
"integer"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"Prompt": {
|
"Prompt": {
|
||||||
"description": "A prompt or prompt template that the server offers.",
|
"description": "A prompt or prompt template that the server offers.",
|
||||||
@@ -1350,9 +1215,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["name"],
|
||||||
"name"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"PromptArgument": {
|
"PromptArgument": {
|
||||||
@@ -1371,9 +1234,7 @@
|
|||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["name"],
|
||||||
"name"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"PromptListChangedNotification": {
|
"PromptListChangedNotification": {
|
||||||
@@ -1395,9 +1256,7 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method"],
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"PromptMessage": {
|
"PromptMessage": {
|
||||||
@@ -1423,10 +1282,7 @@
|
|||||||
"$ref": "#/definitions/Role"
|
"$ref": "#/definitions/Role"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["content", "role"],
|
||||||
"content",
|
|
||||||
"role"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"PromptReference": {
|
"PromptReference": {
|
||||||
@@ -1441,10 +1297,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["name", "type"],
|
||||||
"name",
|
|
||||||
"type"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ReadResourceRequest": {
|
"ReadResourceRequest": {
|
||||||
@@ -1462,16 +1315,11 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["uri"],
|
||||||
"uri"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method", "params"],
|
||||||
"method",
|
|
||||||
"params"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ReadResourceResult": {
|
"ReadResourceResult": {
|
||||||
@@ -1496,9 +1344,7 @@
|
|||||||
"type": "array"
|
"type": "array"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["contents"],
|
||||||
"contents"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"Request": {
|
"Request": {
|
||||||
@@ -1522,17 +1368,12 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method"],
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"RequestId": {
|
"RequestId": {
|
||||||
"description": "A uniquely identifying ID for a request in JSON-RPC.",
|
"description": "A uniquely identifying ID for a request in JSON-RPC.",
|
||||||
"type": [
|
"type": ["string", "integer"]
|
||||||
"string",
|
|
||||||
"integer"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"Resource": {
|
"Resource": {
|
||||||
"description": "A known resource that the server is capable of reading.",
|
"description": "A known resource that the server is capable of reading.",
|
||||||
@@ -1559,10 +1400,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["name", "uri"],
|
||||||
"name",
|
|
||||||
"uri"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ResourceContents": {
|
"ResourceContents": {
|
||||||
@@ -1578,9 +1416,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["uri"],
|
||||||
"uri"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ResourceListChangedNotification": {
|
"ResourceListChangedNotification": {
|
||||||
@@ -1602,9 +1438,7 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method"],
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ResourceReference": {
|
"ResourceReference": {
|
||||||
@@ -1620,10 +1454,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["type", "uri"],
|
||||||
"type",
|
|
||||||
"uri"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ResourceTemplate": {
|
"ResourceTemplate": {
|
||||||
@@ -1651,10 +1482,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["name", "uriTemplate"],
|
||||||
"name",
|
|
||||||
"uriTemplate"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ResourceUpdatedNotification": {
|
"ResourceUpdatedNotification": {
|
||||||
@@ -1672,16 +1500,11 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["uri"],
|
||||||
"uri"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method", "params"],
|
||||||
"method",
|
|
||||||
"params"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"Result": {
|
"Result": {
|
||||||
@@ -1697,10 +1520,7 @@
|
|||||||
},
|
},
|
||||||
"Role": {
|
"Role": {
|
||||||
"description": "The sender or recipient of messages and data in a conversation.",
|
"description": "The sender or recipient of messages and data in a conversation.",
|
||||||
"enum": [
|
"enum": ["assistant", "user"],
|
||||||
"assistant",
|
|
||||||
"user"
|
|
||||||
],
|
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"Root": {
|
"Root": {
|
||||||
@@ -1716,9 +1536,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["uri"],
|
||||||
"uri"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"RootsListChangedNotification": {
|
"RootsListChangedNotification": {
|
||||||
@@ -1740,9 +1558,7 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method"],
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"SamplingMessage": {
|
"SamplingMessage": {
|
||||||
@@ -1765,10 +1581,7 @@
|
|||||||
"$ref": "#/definitions/Role"
|
"$ref": "#/definitions/Role"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["content", "role"],
|
||||||
"content",
|
|
||||||
"role"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ServerCapabilities": {
|
"ServerCapabilities": {
|
||||||
@@ -1915,16 +1728,11 @@
|
|||||||
"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."
|
"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": [
|
"required": ["level"],
|
||||||
"level"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method", "params"],
|
||||||
"method",
|
|
||||||
"params"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"SubscribeRequest": {
|
"SubscribeRequest": {
|
||||||
@@ -1942,16 +1750,11 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["uri"],
|
||||||
"uri"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method", "params"],
|
||||||
"method",
|
|
||||||
"params"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"TextContent": {
|
"TextContent": {
|
||||||
@@ -1970,10 +1773,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["text", "type"],
|
||||||
"text",
|
|
||||||
"type"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"TextResourceContents": {
|
"TextResourceContents": {
|
||||||
@@ -1992,10 +1792,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["text", "uri"],
|
||||||
"text",
|
|
||||||
"uri"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"Tool": {
|
"Tool": {
|
||||||
@@ -2031,9 +1828,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["type"],
|
||||||
"type"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
@@ -2041,10 +1836,7 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["inputSchema", "name"],
|
||||||
"inputSchema",
|
|
||||||
"name"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"ToolAnnotations": {
|
"ToolAnnotations": {
|
||||||
@@ -2092,9 +1884,7 @@
|
|||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method"],
|
||||||
"method"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
},
|
},
|
||||||
"UnsubscribeRequest": {
|
"UnsubscribeRequest": {
|
||||||
@@ -2112,16 +1902,11 @@
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["uri"],
|
||||||
"uri"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": ["method", "params"],
|
||||||
"method",
|
|
||||||
"params"
|
|
||||||
],
|
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,7 @@ export async function someAiOperationDirect(args, log, context) {
|
|||||||
model: modelConfig.model,
|
model: modelConfig.model,
|
||||||
max_tokens: modelConfig.maxTokens,
|
max_tokens: modelConfig.maxTokens,
|
||||||
temperature: modelConfig.temperature,
|
temperature: modelConfig.temperature,
|
||||||
messages: [
|
messages: [{ role: 'user', content: 'Your prompt here' }]
|
||||||
{ role: 'user', content: 'Your prompt here' }
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -64,7 +62,10 @@ export async function someAiOperationDirect(args, log, context) {
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// In your MCP tool implementation:
|
// 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';
|
import { someAiOperationDirect } from '../../core/direct-functions/some-ai-operation.js';
|
||||||
|
|
||||||
export async function someAiOperation(args, context) {
|
export async function someAiOperation(args, context) {
|
||||||
@@ -87,15 +88,11 @@ export async function someAiOperation(args, context) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Call direct function with session and progress reporting
|
// Call direct function with session and progress reporting
|
||||||
const result = await someAiOperationDirect(
|
const result = await someAiOperationDirect(args, log, {
|
||||||
args,
|
|
||||||
log,
|
|
||||||
{
|
|
||||||
reportProgress,
|
reportProgress,
|
||||||
mcpLog: log,
|
mcpLog: log,
|
||||||
session
|
session
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
// Final progress update
|
// Final progress update
|
||||||
reportProgress({
|
reportProgress({
|
||||||
@@ -178,9 +175,7 @@ export async function researchOperationDirect(args, log, context) {
|
|||||||
// Call Perplexity
|
// Call Perplexity
|
||||||
const response = await client.chat.completions.create({
|
const response = await client.chat.completions.create({
|
||||||
model: context.session?.env?.PERPLEXITY_MODEL || 'sonar-medium-online',
|
model: context.session?.env?.PERPLEXITY_MODEL || 'sonar-medium-online',
|
||||||
messages: [
|
messages: [{ role: 'user', content: args.researchQuery }],
|
||||||
{ role: 'user', content: args.researchQuery }
|
|
||||||
],
|
|
||||||
temperature: 0.1
|
temperature: 0.1
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -226,7 +221,7 @@ const modelConfig = getModelConfig(context.session, operationDefaults);
|
|||||||
const response = await client.messages.create({
|
const response = await client.messages.create({
|
||||||
model: modelConfig.model,
|
model: modelConfig.model,
|
||||||
max_tokens: modelConfig.maxTokens,
|
max_tokens: modelConfig.maxTokens,
|
||||||
temperature: modelConfig.temperature,
|
temperature: modelConfig.temperature
|
||||||
// Other parameters...
|
// Other parameters...
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
@@ -234,20 +229,24 @@ const response = await client.messages.create({
|
|||||||
## Best Practices
|
## Best Practices
|
||||||
|
|
||||||
1. **Error Handling**:
|
1. **Error Handling**:
|
||||||
|
|
||||||
- Always use try/catch blocks around both client initialization and API calls
|
- Always use try/catch blocks around both client initialization and API calls
|
||||||
- Use `handleClaudeError` to provide user-friendly error messages
|
- Use `handleClaudeError` to provide user-friendly error messages
|
||||||
- Return standardized error objects with code and message
|
- Return standardized error objects with code and message
|
||||||
|
|
||||||
2. **Progress Reporting**:
|
2. **Progress Reporting**:
|
||||||
|
|
||||||
- Report progress at key points (starting, processing, completing)
|
- Report progress at key points (starting, processing, completing)
|
||||||
- Include meaningful status messages
|
- Include meaningful status messages
|
||||||
- Include error details in progress reports when failures occur
|
- Include error details in progress reports when failures occur
|
||||||
|
|
||||||
3. **Session Handling**:
|
3. **Session Handling**:
|
||||||
|
|
||||||
- Always pass the session from the context to the AI client getters
|
- Always pass the session from the context to the AI client getters
|
||||||
- Use `getModelConfig` to respect user settings from session
|
- Use `getModelConfig` to respect user settings from session
|
||||||
|
|
||||||
4. **Model Selection**:
|
4. **Model Selection**:
|
||||||
|
|
||||||
- Use `getBestAvailableAIModel` when you need to select between different models
|
- Use `getBestAvailableAIModel` when you need to select between different models
|
||||||
- Set `requiresResearch: true` when you need Perplexity capabilities
|
- Set `requiresResearch: true` when you need Perplexity capabilities
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ MCP (Model Control Protocol) provides the easiest way to get started with Task M
|
|||||||
"mcpServers": {
|
"mcpServers": {
|
||||||
"taskmaster-ai": {
|
"taskmaster-ai": {
|
||||||
"command": "npx",
|
"command": "npx",
|
||||||
"args": ["-y", "task-master-ai", "mcp-server"],
|
"args": ["-y", "--package", "task-master-ai", "task-master-mcp"],
|
||||||
"env": {
|
"env": {
|
||||||
"ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE",
|
"ANTHROPIC_API_KEY": "YOUR_ANTHROPIC_API_KEY_HERE",
|
||||||
"PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE",
|
"PERPLEXITY_API_KEY": "YOUR_PERPLEXITY_API_KEY_HERE",
|
||||||
|
|||||||
41
entries.json
41
entries.json
@@ -1,41 +0,0 @@
|
|||||||
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}.")
|
|
||||||
2
index.js
2
index.js
@@ -80,7 +80,7 @@ if (import.meta.url === `file://${process.argv[1]}`) {
|
|||||||
.command('init')
|
.command('init')
|
||||||
.description('Initialize a new project')
|
.description('Initialize a new project')
|
||||||
.action(() => {
|
.action(() => {
|
||||||
runInitCLI().catch(err => {
|
runInitCLI().catch((err) => {
|
||||||
console.error('Init failed:', err.message);
|
console.error('Init failed:', err.message);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import TaskMasterMCPServer from "./src/index.js";
|
import TaskMasterMCPServer from './src/index.js';
|
||||||
import dotenv from "dotenv";
|
import dotenv from 'dotenv';
|
||||||
import logger from "./src/logger.js";
|
import logger from './src/logger.js';
|
||||||
|
|
||||||
// Load environment variables
|
// Load environment variables
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
@@ -14,12 +14,12 @@ async function startServer() {
|
|||||||
const server = new TaskMasterMCPServer();
|
const server = new TaskMasterMCPServer();
|
||||||
|
|
||||||
// Handle graceful shutdown
|
// Handle graceful shutdown
|
||||||
process.on("SIGINT", async () => {
|
process.on('SIGINT', async () => {
|
||||||
await server.stop();
|
await server.stop();
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on("SIGTERM", async () => {
|
process.on('SIGTERM', async () => {
|
||||||
await server.stop();
|
await server.stop();
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ describe('ContextManager', () => {
|
|||||||
|
|
||||||
describe('getContext', () => {
|
describe('getContext', () => {
|
||||||
it('should create a new context when not in cache', async () => {
|
it('should create a new context when not in cache', async () => {
|
||||||
const context = await contextManager.getContext('test-id', { test: true });
|
const context = await contextManager.getContext('test-id', {
|
||||||
|
test: true
|
||||||
|
});
|
||||||
expect(context.id).toBe('test-id');
|
expect(context.id).toBe('test-id');
|
||||||
expect(context.metadata.test).toBe(true);
|
expect(context.metadata.test).toBe(true);
|
||||||
expect(contextManager.stats.misses).toBe(1);
|
expect(contextManager.stats.misses).toBe(1);
|
||||||
@@ -26,7 +28,9 @@ describe('ContextManager', () => {
|
|||||||
await contextManager.getContext('test-id', { test: true });
|
await contextManager.getContext('test-id', { test: true });
|
||||||
|
|
||||||
// Second call should hit cache
|
// 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.id).toBe('test-id');
|
||||||
expect(context.metadata.test).toBe(true);
|
expect(context.metadata.test).toBe(true);
|
||||||
expect(contextManager.stats.hits).toBe(1);
|
expect(contextManager.stats.hits).toBe(1);
|
||||||
@@ -38,7 +42,7 @@ describe('ContextManager', () => {
|
|||||||
await contextManager.getContext('test-id', { test: true });
|
await contextManager.getContext('test-id', { test: true });
|
||||||
|
|
||||||
// Wait for TTL to expire
|
// Wait for TTL to expire
|
||||||
await new Promise(resolve => setTimeout(resolve, 1100));
|
await new Promise((resolve) => setTimeout(resolve, 1100));
|
||||||
|
|
||||||
// Should create new context
|
// Should create new context
|
||||||
await contextManager.getContext('test-id', { test: true });
|
await contextManager.getContext('test-id', { test: true });
|
||||||
@@ -50,7 +54,9 @@ describe('ContextManager', () => {
|
|||||||
describe('updateContext', () => {
|
describe('updateContext', () => {
|
||||||
it('should update existing context metadata', async () => {
|
it('should update existing context metadata', async () => {
|
||||||
await contextManager.getContext('test-id', { initial: true });
|
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.initial).toBe(true);
|
||||||
expect(updated.metadata.updated).toBe(true);
|
expect(updated.metadata.updated).toBe(true);
|
||||||
|
|||||||
@@ -112,7 +112,8 @@ export class ContextManager {
|
|||||||
*/
|
*/
|
||||||
getCachedData(key) {
|
getCachedData(key) {
|
||||||
const cached = this.cache.get(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++;
|
this.stats.hits++;
|
||||||
return cached;
|
return cached;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,10 @@
|
|||||||
|
|
||||||
import { addDependency } from '../../../../scripts/modules/dependency-manager.js';
|
import { addDependency } from '../../../../scripts/modules/dependency-manager.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
import {
|
||||||
|
enableSilentMode,
|
||||||
|
disableSilentMode
|
||||||
|
} from '../../../../scripts/modules/utils.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Direct function wrapper for addDependency with error handling.
|
* Direct function wrapper for addDependency with error handling.
|
||||||
@@ -18,7 +21,7 @@ import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules
|
|||||||
* @param {Object} log - Logger object
|
* @param {Object} log - Logger object
|
||||||
* @returns {Promise<Object>} - Result object with success status and data/error information
|
* @returns {Promise<Object>} - Result object with success status and data/error information
|
||||||
*/
|
*/
|
||||||
export async function addDependencyDirect(args, log) {
|
export async function addDependencyDirect(args, log, { session }) {
|
||||||
try {
|
try {
|
||||||
log.info(`Adding dependency with args: ${JSON.stringify(args)}`);
|
log.info(`Adding dependency with args: ${JSON.stringify(args)}`);
|
||||||
|
|
||||||
@@ -44,13 +47,21 @@ export async function addDependencyDirect(args, log) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the tasks.json path
|
// Find the tasks.json path
|
||||||
const tasksPath = findTasksJsonPath(args, log);
|
const tasksPath = findTasksJsonPath(args, log, session);
|
||||||
|
|
||||||
// Format IDs for the core function
|
// Format IDs for the core function
|
||||||
const taskId = args.id.includes && args.id.includes('.') ? args.id : parseInt(args.id, 10);
|
const taskId =
|
||||||
const dependencyId = args.dependsOn.includes && args.dependsOn.includes('.') ? args.dependsOn : parseInt(args.dependsOn, 10);
|
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
|
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||||
enableSilentMode();
|
enableSilentMode();
|
||||||
|
|||||||
@@ -4,7 +4,10 @@
|
|||||||
|
|
||||||
import { addSubtask } from '../../../../scripts/modules/task-manager.js';
|
import { addSubtask } from '../../../../scripts/modules/task-manager.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
import {
|
||||||
|
enableSilentMode,
|
||||||
|
disableSilentMode
|
||||||
|
} from '../../../../scripts/modules/utils.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a subtask to an existing task
|
* Add a subtask to an existing task
|
||||||
@@ -22,7 +25,7 @@ import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules
|
|||||||
* @param {Object} log - Logger object
|
* @param {Object} log - Logger object
|
||||||
* @returns {Promise<{success: boolean, data?: Object, error?: string}>}
|
* @returns {Promise<{success: boolean, data?: Object, error?: string}>}
|
||||||
*/
|
*/
|
||||||
export async function addSubtaskDirect(args, log) {
|
export async function addSubtaskDirect(args, log, { session }) {
|
||||||
try {
|
try {
|
||||||
log.info(`Adding subtask with args: ${JSON.stringify(args)}`);
|
log.info(`Adding subtask with args: ${JSON.stringify(args)}`);
|
||||||
|
|
||||||
@@ -48,12 +51,12 @@ export async function addSubtaskDirect(args, log) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the tasks.json path
|
// Find the tasks.json path
|
||||||
const tasksPath = findTasksJsonPath(args, log);
|
const tasksPath = findTasksJsonPath(args, log, session);
|
||||||
|
|
||||||
// Parse dependencies if provided
|
// Parse dependencies if provided
|
||||||
let dependencies = [];
|
let dependencies = [];
|
||||||
if (args.dependencies) {
|
if (args.dependencies) {
|
||||||
dependencies = args.dependencies.split(',').map(id => {
|
dependencies = args.dependencies.split(',').map((id) => {
|
||||||
// Handle both regular IDs and dot notation
|
// Handle both regular IDs and dot notation
|
||||||
return id.includes('.') ? id.trim() : parseInt(id.trim(), 10);
|
return id.includes('.') ? id.trim() : parseInt(id.trim(), 10);
|
||||||
});
|
});
|
||||||
@@ -74,7 +77,13 @@ export async function addSubtaskDirect(args, log) {
|
|||||||
// Case 1: Convert existing task to subtask
|
// Case 1: Convert existing task to subtask
|
||||||
if (existingTaskId) {
|
if (existingTaskId) {
|
||||||
log.info(`Converting task ${existingTaskId} to a subtask of ${parentId}`);
|
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
|
// Restore normal logging
|
||||||
disableSilentMode();
|
disableSilentMode();
|
||||||
@@ -99,7 +108,13 @@ export async function addSubtaskDirect(args, log) {
|
|||||||
dependencies: dependencies
|
dependencies: dependencies
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = await addSubtask(tasksPath, parentId, null, newSubtaskData, generateFiles);
|
const result = await addSubtask(
|
||||||
|
tasksPath,
|
||||||
|
parentId,
|
||||||
|
null,
|
||||||
|
newSubtaskData,
|
||||||
|
generateFiles
|
||||||
|
);
|
||||||
|
|
||||||
// Restore normal logging
|
// Restore normal logging
|
||||||
disableSilentMode();
|
disableSilentMode();
|
||||||
|
|||||||
@@ -5,41 +5,61 @@
|
|||||||
|
|
||||||
import { addTask } from '../../../../scripts/modules/task-manager.js';
|
import { addTask } from '../../../../scripts/modules/task-manager.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
import {
|
||||||
import { getAnthropicClientForMCP, getModelConfig } from '../utils/ai-client-utils.js';
|
enableSilentMode,
|
||||||
import { _buildAddTaskPrompt, parseTaskJsonResponse, _handleAnthropicStream } from '../../../../scripts/modules/ai-services.js';
|
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.
|
* Direct function wrapper for adding a new task with error handling.
|
||||||
*
|
*
|
||||||
* @param {Object} args - Command arguments
|
* @param {Object} args - Command arguments
|
||||||
* @param {string} args.prompt - Description of the task to add
|
* @param {string} [args.prompt] - Description of the task to add (required if not using manual fields)
|
||||||
* @param {Array<number>} [args.dependencies=[]] - Task dependencies as array of IDs
|
* @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.priority='medium'] - Task priority (high, medium, low)
|
* @param {string} [args.priority='medium'] - Task priority (high, medium, low)
|
||||||
* @param {string} [args.file] - Path to the tasks file
|
* @param {string} [args.file='tasks/tasks.json'] - Path to the tasks file
|
||||||
* @param {string} [args.projectRoot] - Project root directory
|
* @param {string} [args.projectRoot] - Project root directory
|
||||||
* @param {boolean} [args.research] - Whether to use research capabilities for task creation
|
* @param {boolean} [args.research=false] - Whether to use research capabilities for task creation
|
||||||
* @param {Object} log - Logger object
|
* @param {Object} log - Logger object
|
||||||
* @param {Object} context - Additional context (reportProgress, session)
|
* @param {Object} context - Additional context (reportProgress, session)
|
||||||
* @returns {Promise<Object>} - Result object { success: boolean, data?: any, error?: { code: string, message: string } }
|
* @returns {Promise<Object>} - Result object { success: boolean, data?: any, error?: { code: string, message: string } }
|
||||||
*/
|
*/
|
||||||
export async function addTaskDirect(args, log, context = {}) {
|
export async function addTaskDirect(args, log, { session }) {
|
||||||
try {
|
try {
|
||||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||||
enableSilentMode();
|
enableSilentMode();
|
||||||
|
|
||||||
// Find the tasks.json path
|
// Find the tasks.json path
|
||||||
const tasksPath = findTasksJsonPath(args, log);
|
const tasksPath = findTasksJsonPath(args, log, session);
|
||||||
|
|
||||||
|
// Check if this is manual task creation or AI-driven task creation
|
||||||
|
const isManualCreation = args.title && args.description;
|
||||||
|
|
||||||
// Check required parameters
|
// Check required parameters
|
||||||
if (!args.prompt) {
|
if (!args.prompt && !isManualCreation) {
|
||||||
log.error('Missing required parameter: prompt');
|
log.error(
|
||||||
|
'Missing required parameters: either prompt or title+description must be provided'
|
||||||
|
);
|
||||||
disableSilentMode();
|
disableSilentMode();
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: {
|
error: {
|
||||||
code: 'MISSING_PARAMETER',
|
code: 'MISSING_PARAMETER',
|
||||||
message: 'The prompt parameter is required for adding a task'
|
message:
|
||||||
|
'Either the prompt parameter or both title and description parameters are required for adding a task'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -48,15 +68,58 @@ export async function addTaskDirect(args, log, context = {}) {
|
|||||||
const prompt = args.prompt;
|
const prompt = args.prompt;
|
||||||
const dependencies = Array.isArray(args.dependencies)
|
const dependencies = Array.isArray(args.dependencies)
|
||||||
? args.dependencies
|
? args.dependencies
|
||||||
: (args.dependencies ? String(args.dependencies).split(',').map(id => parseInt(id.trim(), 10)) : []);
|
: args.dependencies
|
||||||
|
? String(args.dependencies)
|
||||||
|
.split(',')
|
||||||
|
.map((id) => parseInt(id.trim(), 10))
|
||||||
|
: [];
|
||||||
const priority = args.priority || 'medium';
|
const priority = args.priority || 'medium';
|
||||||
|
|
||||||
log.info(`Adding new task with prompt: "${prompt}", dependencies: [${dependencies.join(', ')}], priority: ${priority}`);
|
let manualTaskData = null;
|
||||||
|
|
||||||
// Extract context parameters for advanced functionality
|
if (isManualCreation) {
|
||||||
// Commenting out reportProgress extraction
|
// Create manual task data object
|
||||||
// const { reportProgress, session } = context;
|
manualTaskData = {
|
||||||
const { session } = context; // Keep session
|
title: args.title,
|
||||||
|
description: args.description,
|
||||||
|
details: args.details || '',
|
||||||
|
testStrategy: args.testStrategy || ''
|
||||||
|
};
|
||||||
|
|
||||||
|
log.info(
|
||||||
|
`Adding new task manually with title: "${args.title}", dependencies: [${dependencies.join(', ')}], priority: ${priority}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// Call the addTask function with manual task data
|
||||||
|
const newTaskId = await addTask(
|
||||||
|
tasksPath,
|
||||||
|
null, // No prompt needed for manual creation
|
||||||
|
dependencies,
|
||||||
|
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: [${dependencies.join(', ')}], priority: ${priority}`
|
||||||
|
);
|
||||||
|
|
||||||
// Initialize AI client with session environment
|
// Initialize AI client with session environment
|
||||||
let localAnthropic;
|
let localAnthropic;
|
||||||
@@ -88,7 +151,10 @@ export async function addTaskDirect(args, log, context = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build prompts for AI
|
// 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
|
// Make the AI call using the streaming helper
|
||||||
let responseText;
|
let responseText;
|
||||||
@@ -99,11 +165,10 @@ export async function addTaskDirect(args, log, context = {}) {
|
|||||||
model: modelConfig.model,
|
model: modelConfig.model,
|
||||||
max_tokens: modelConfig.maxTokens,
|
max_tokens: modelConfig.maxTokens,
|
||||||
temperature: modelConfig.temperature,
|
temperature: modelConfig.temperature,
|
||||||
messages: [{ role: "user", content: userPrompt }],
|
messages: [{ role: 'user', content: userPrompt }],
|
||||||
system: systemPrompt
|
system: systemPrompt
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// reportProgress: context.reportProgress, // Commented out to prevent Cursor stroking out
|
|
||||||
mcpLog: log
|
mcpLog: log
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -142,12 +207,12 @@ export async function addTaskDirect(args, log, context = {}) {
|
|||||||
dependencies,
|
dependencies,
|
||||||
priority,
|
priority,
|
||||||
{
|
{
|
||||||
// reportProgress, // Commented out
|
|
||||||
mcpLog: log,
|
mcpLog: log,
|
||||||
session,
|
session
|
||||||
taskDataFromAI // Pass the parsed AI result
|
|
||||||
},
|
},
|
||||||
'json'
|
'json',
|
||||||
|
null,
|
||||||
|
taskDataFromAI // Pass the parsed AI result as the manual task data
|
||||||
);
|
);
|
||||||
|
|
||||||
// Restore normal logging
|
// Restore normal logging
|
||||||
@@ -160,6 +225,7 @@ export async function addTaskDirect(args, log, context = {}) {
|
|||||||
message: `Successfully added new task #${newTaskId}`
|
message: `Successfully added new task #${newTaskId}`
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Make sure to restore normal logging even if there's an error
|
// Make sure to restore normal logging even if there's an error
|
||||||
disableSilentMode();
|
disableSilentMode();
|
||||||
|
|||||||
@@ -3,8 +3,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { analyzeTaskComplexity } from '../../../../scripts/modules/task-manager.js';
|
import { analyzeTaskComplexity } from '../../../../scripts/modules/task-manager.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import {
|
||||||
import { enableSilentMode, disableSilentMode, isSilentMode, readJSON } from '../../../../scripts/modules/utils.js';
|
findTasksJsonPath,
|
||||||
|
resolveProjectPath,
|
||||||
|
ensureDirectoryExists
|
||||||
|
} from '../utils/path-utils.js';
|
||||||
|
import {
|
||||||
|
enableSilentMode,
|
||||||
|
disableSilentMode,
|
||||||
|
isSilentMode,
|
||||||
|
readJSON
|
||||||
|
} from '../../../../scripts/modules/utils.js';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
@@ -21,23 +30,33 @@ import path from 'path';
|
|||||||
* @param {Object} [context={}] - Context object containing session data
|
* @param {Object} [context={}] - Context object containing session data
|
||||||
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
||||||
*/
|
*/
|
||||||
export async function analyzeTaskComplexityDirect(args, log, context = {}) {
|
export async function analyzeTaskComplexityDirect(args, log, { session }) {
|
||||||
const { session } = context; // Only extract session, not reportProgress
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.info(`Analyzing task complexity with args: ${JSON.stringify(args)}`);
|
log.info(`Analyzing task complexity with args: ${JSON.stringify(args)}`);
|
||||||
|
|
||||||
// Find the tasks.json path
|
// Find the tasks.json path AND get the validated project root
|
||||||
const tasksPath = findTasksJsonPath(args, log);
|
const { tasksPath, validatedProjectRoot } = findTasksJsonPath(
|
||||||
|
args,
|
||||||
|
log,
|
||||||
|
session
|
||||||
|
);
|
||||||
|
log.info(
|
||||||
|
`Using tasks file: ${tasksPath} located within project root: ${validatedProjectRoot}`
|
||||||
|
);
|
||||||
|
|
||||||
// Determine output path
|
// Determine and resolve the output path using the VALIDATED root
|
||||||
let outputPath = args.output || 'scripts/task-complexity-report.json';
|
const relativeOutputPath =
|
||||||
if (!path.isAbsolute(outputPath) && args.projectRoot) {
|
args.output || 'scripts/task-complexity-report.json';
|
||||||
outputPath = path.join(args.projectRoot, outputPath);
|
const absoluteOutputPath = resolveProjectPath(
|
||||||
}
|
relativeOutputPath,
|
||||||
|
validatedProjectRoot,
|
||||||
|
log
|
||||||
|
);
|
||||||
|
|
||||||
log.info(`Analyzing task complexity from: ${tasksPath}`);
|
// Ensure the output directory exists
|
||||||
log.info(`Output report will be saved to: ${outputPath}`);
|
ensureDirectoryExists(path.dirname(absoluteOutputPath), log);
|
||||||
|
|
||||||
|
log.info(`Output report will be saved to: ${absoluteOutputPath}`);
|
||||||
|
|
||||||
if (args.research) {
|
if (args.research) {
|
||||||
log.info('Using Perplexity AI for research-backed complexity analysis');
|
log.info('Using Perplexity AI for research-backed complexity analysis');
|
||||||
@@ -46,7 +65,7 @@ export async function analyzeTaskComplexityDirect(args, log, context = {}) {
|
|||||||
// Create options object for analyzeTaskComplexity
|
// Create options object for analyzeTaskComplexity
|
||||||
const options = {
|
const options = {
|
||||||
file: tasksPath,
|
file: tasksPath,
|
||||||
output: outputPath,
|
output: absoluteOutputPath,
|
||||||
model: args.model,
|
model: args.model,
|
||||||
threshold: args.threshold,
|
threshold: args.threshold,
|
||||||
research: args.research === true
|
research: args.research === true
|
||||||
@@ -90,7 +109,7 @@ export async function analyzeTaskComplexityDirect(args, log, context = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verify the report file was created
|
// Verify the report file was created
|
||||||
if (!fs.existsSync(outputPath)) {
|
if (!fs.existsSync(absoluteOutputPath)) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: {
|
error: {
|
||||||
@@ -103,23 +122,30 @@ export async function analyzeTaskComplexityDirect(args, log, context = {}) {
|
|||||||
// Read the report file
|
// Read the report file
|
||||||
let report;
|
let report;
|
||||||
try {
|
try {
|
||||||
report = JSON.parse(fs.readFileSync(outputPath, 'utf8'));
|
report = JSON.parse(fs.readFileSync(absoluteOutputPath, 'utf8'));
|
||||||
|
|
||||||
// Important: Handle different report formats
|
// Important: Handle different report formats
|
||||||
// The core function might return an array or an object with a complexityAnalysis property
|
// The core function might return an array or an object with a complexityAnalysis property
|
||||||
const analysisArray = Array.isArray(report) ? report :
|
const analysisArray = Array.isArray(report)
|
||||||
(report.complexityAnalysis || []);
|
? report
|
||||||
|
: report.complexityAnalysis || [];
|
||||||
|
|
||||||
// Count tasks by complexity
|
// Count tasks by complexity
|
||||||
const highComplexityTasks = analysisArray.filter(t => t.complexityScore >= 8).length;
|
const highComplexityTasks = analysisArray.filter(
|
||||||
const mediumComplexityTasks = analysisArray.filter(t => t.complexityScore >= 5 && t.complexityScore < 8).length;
|
(t) => t.complexityScore >= 8
|
||||||
const lowComplexityTasks = analysisArray.filter(t => t.complexityScore < 5).length;
|
).length;
|
||||||
|
const mediumComplexityTasks = analysisArray.filter(
|
||||||
|
(t) => t.complexityScore >= 5 && t.complexityScore < 8
|
||||||
|
).length;
|
||||||
|
const lowComplexityTasks = analysisArray.filter(
|
||||||
|
(t) => t.complexityScore < 5
|
||||||
|
).length;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data: {
|
data: {
|
||||||
message: `Task complexity analysis complete. Report saved to ${outputPath}`,
|
message: `Task complexity analysis complete. Report saved to ${absoluteOutputPath}`,
|
||||||
reportPath: outputPath,
|
reportPath: absoluteOutputPath,
|
||||||
reportSummary: {
|
reportSummary: {
|
||||||
taskCount: analysisArray.length,
|
taskCount: analysisArray.length,
|
||||||
highComplexityTasks,
|
highComplexityTasks,
|
||||||
@@ -139,18 +165,23 @@ export async function analyzeTaskComplexityDirect(args, log, context = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Make sure to restore normal logging even if there's an error
|
// Centralized error catching for issues like invalid root, file not found, core errors etc.
|
||||||
if (isSilentMode()) {
|
if (isSilentMode()) {
|
||||||
disableSilentMode();
|
disableSilentMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
log.error(`Error in analyzeTaskComplexityDirect: ${error.message}`);
|
log.error(`Error in analyzeTaskComplexityDirect: ${error.message}`, {
|
||||||
|
code: error.code,
|
||||||
|
details: error.details,
|
||||||
|
stack: error.stack
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: {
|
error: {
|
||||||
code: 'CORE_FUNCTION_ERROR',
|
code: error.code || 'ANALYZE_COMPLEXITY_ERROR',
|
||||||
message: error.message
|
message: error.message
|
||||||
}
|
},
|
||||||
|
fromCache: false // Assume errors are not from cache
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,10 @@
|
|||||||
|
|
||||||
import { clearSubtasks } from '../../../../scripts/modules/task-manager.js';
|
import { clearSubtasks } from '../../../../scripts/modules/task-manager.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
import {
|
||||||
|
enableSilentMode,
|
||||||
|
disableSilentMode
|
||||||
|
} from '../../../../scripts/modules/utils.js';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,7 +20,7 @@ import fs from 'fs';
|
|||||||
* @param {Object} log - Logger object
|
* @param {Object} log - Logger object
|
||||||
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
||||||
*/
|
*/
|
||||||
export async function clearSubtasksDirect(args, log) {
|
export async function clearSubtasksDirect(args, log, { session }) {
|
||||||
try {
|
try {
|
||||||
log.info(`Clearing subtasks with args: ${JSON.stringify(args)}`);
|
log.info(`Clearing subtasks with args: ${JSON.stringify(args)}`);
|
||||||
|
|
||||||
@@ -27,13 +30,14 @@ export async function clearSubtasksDirect(args, log) {
|
|||||||
success: false,
|
success: false,
|
||||||
error: {
|
error: {
|
||||||
code: 'INPUT_VALIDATION_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'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find the tasks.json path
|
// Find the tasks.json path
|
||||||
const tasksPath = findTasksJsonPath(args, log);
|
const tasksPath = findTasksJsonPath(args, log, session);
|
||||||
|
|
||||||
// Check if tasks.json exists
|
// Check if tasks.json exists
|
||||||
if (!fs.existsSync(tasksPath)) {
|
if (!fs.existsSync(tasksPath)) {
|
||||||
@@ -61,7 +65,7 @@ export async function clearSubtasksDirect(args, log) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
taskIds = data.tasks.map(t => t.id).join(',');
|
taskIds = data.tasks.map((t) => t.id).join(',');
|
||||||
} else {
|
} else {
|
||||||
// Use the provided task IDs
|
// Use the provided task IDs
|
||||||
taskIds = args.id;
|
taskIds = args.id;
|
||||||
@@ -80,12 +84,12 @@ export async function clearSubtasksDirect(args, log) {
|
|||||||
|
|
||||||
// Read the updated data to provide a summary
|
// Read the updated data to provide a summary
|
||||||
const updatedData = JSON.parse(fs.readFileSync(tasksPath, 'utf8'));
|
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
|
// Build a summary of what was done
|
||||||
const clearedTasksCount = taskIdArray.length;
|
const clearedTasksCount = taskIdArray.length;
|
||||||
const taskSummary = taskIdArray.map(id => {
|
const taskSummary = taskIdArray.map((id) => {
|
||||||
const task = updatedData.tasks.find(t => t.id === id);
|
const task = updatedData.tasks.find((t) => t.id === id);
|
||||||
return task ? { id, title: task.title } : { id, title: 'Task not found' };
|
return task ? { id, title: task.title } : { id, title: 'Task not found' };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,11 @@
|
|||||||
* Direct function implementation for displaying complexity analysis report
|
* 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 { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { getCachedOrExecute } from '../../tools/utils.js';
|
import { getCachedOrExecute } from '../../tools/utils.js';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
@@ -15,21 +19,25 @@ import path from 'path';
|
|||||||
* @param {Object} log - Logger object
|
* @param {Object} log - Logger object
|
||||||
* @returns {Promise<Object>} - Result object with success status and data/error information
|
* @returns {Promise<Object>} - Result object with success status and data/error information
|
||||||
*/
|
*/
|
||||||
export async function complexityReportDirect(args, log) {
|
export async function complexityReportDirect(args, log, { session }) {
|
||||||
try {
|
try {
|
||||||
log.info(`Getting complexity report with args: ${JSON.stringify(args)}`);
|
log.info(`Getting complexity report with args: ${JSON.stringify(args)}`);
|
||||||
|
|
||||||
// Get tasks file path to determine project root for the default report location
|
// Get tasks file path to determine project root for the default report location
|
||||||
let tasksPath;
|
let tasksPath;
|
||||||
try {
|
try {
|
||||||
tasksPath = findTasksJsonPath(args, log);
|
tasksPath = findTasksJsonPath(args, log, session);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.warn(`Tasks file not found, using current directory: ${error.message}`);
|
log.warn(
|
||||||
|
`Tasks file not found, using current directory: ${error.message}`
|
||||||
|
);
|
||||||
// Continue with default or specified report path
|
// Continue with default or specified report path
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get report file path from args or use default
|
// Get report file path from args or use default
|
||||||
const reportPath = args.file || path.join(process.cwd(), 'scripts', 'task-complexity-report.json');
|
const reportPath =
|
||||||
|
args.file ||
|
||||||
|
path.join(process.cwd(), 'scripts', 'task-complexity-report.json');
|
||||||
|
|
||||||
log.info(`Looking for complexity report at: ${reportPath}`);
|
log.info(`Looking for complexity report at: ${reportPath}`);
|
||||||
|
|
||||||
@@ -87,14 +95,18 @@ export async function complexityReportDirect(args, log) {
|
|||||||
actionFn: coreActionFn,
|
actionFn: coreActionFn,
|
||||||
log
|
log
|
||||||
});
|
});
|
||||||
log.info(`complexityReportDirect completed. From cache: ${result.fromCache}`);
|
log.info(
|
||||||
|
`complexityReportDirect completed. From cache: ${result.fromCache}`
|
||||||
|
);
|
||||||
return result; // Returns { success, data/error, fromCache }
|
return result; // Returns { success, data/error, fromCache }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Catch unexpected errors from getCachedOrExecute itself
|
// Catch unexpected errors from getCachedOrExecute itself
|
||||||
// Ensure silent mode is disabled
|
// Ensure silent mode is disabled
|
||||||
disableSilentMode();
|
disableSilentMode();
|
||||||
|
|
||||||
log.error(`Unexpected error during getCachedOrExecute for complexityReport: ${error.message}`);
|
log.error(
|
||||||
|
`Unexpected error during getCachedOrExecute for complexityReport: ${error.message}`
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: {
|
error: {
|
||||||
|
|||||||
@@ -3,7 +3,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { expandAllTasks } from '../../../../scripts/modules/task-manager.js';
|
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 { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { getAnthropicClientForMCP } from '../utils/ai-client-utils.js';
|
import { getAnthropicClientForMCP } from '../utils/ai-client-utils.js';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
@@ -22,9 +26,7 @@ import fs from 'fs';
|
|||||||
* @param {Object} context - Context object containing session
|
* @param {Object} context - Context object containing session
|
||||||
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
||||||
*/
|
*/
|
||||||
export async function expandAllTasksDirect(args, log, context = {}) {
|
export async function expandAllTasksDirect(args, log, { session }) {
|
||||||
const { session } = context; // Only extract session, not reportProgress
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`);
|
log.info(`Expanding all tasks with args: ${JSON.stringify(args)}`);
|
||||||
|
|
||||||
@@ -33,7 +35,7 @@ export async function expandAllTasksDirect(args, log, context = {}) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Find the tasks.json path
|
// Find the tasks.json path
|
||||||
const tasksPath = findTasksJsonPath(args, log);
|
const tasksPath = findTasksJsonPath(args, log, session);
|
||||||
|
|
||||||
// Parse parameters
|
// Parse parameters
|
||||||
const numSubtasks = args.num ? parseInt(args.num, 10) : undefined;
|
const numSubtasks = args.num ? parseInt(args.num, 10) : undefined;
|
||||||
@@ -41,7 +43,9 @@ export async function expandAllTasksDirect(args, log, context = {}) {
|
|||||||
const additionalContext = args.prompt || '';
|
const additionalContext = args.prompt || '';
|
||||||
const forceFlag = args.force === true;
|
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) {
|
if (useResearch) {
|
||||||
log.info('Using Perplexity AI for research-backed subtask generation');
|
log.info('Using Perplexity AI for research-backed subtask generation');
|
||||||
@@ -87,7 +91,7 @@ export async function expandAllTasksDirect(args, log, context = {}) {
|
|||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data: {
|
data: {
|
||||||
message: "Successfully expanded all pending tasks with subtasks",
|
message: 'Successfully expanded all pending tasks with subtasks',
|
||||||
details: {
|
details: {
|
||||||
numSubtasks: numSubtasks,
|
numSubtasks: numSubtasks,
|
||||||
research: useResearch,
|
research: useResearch,
|
||||||
|
|||||||
@@ -4,9 +4,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { expandTask } from '../../../../scripts/modules/task-manager.js';
|
import { expandTask } from '../../../../scripts/modules/task-manager.js';
|
||||||
import { readJSON, writeJSON, enableSilentMode, disableSilentMode, isSilentMode } from '../../../../scripts/modules/utils.js';
|
import {
|
||||||
|
readJSON,
|
||||||
|
writeJSON,
|
||||||
|
enableSilentMode,
|
||||||
|
disableSilentMode,
|
||||||
|
isSilentMode
|
||||||
|
} from '../../../../scripts/modules/utils.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { getAnthropicClientForMCP, getModelConfig } from '../utils/ai-client-utils.js';
|
import {
|
||||||
|
getAnthropicClientForMCP,
|
||||||
|
getModelConfig
|
||||||
|
} from '../utils/ai-client-utils.js';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
@@ -18,38 +27,44 @@ import fs from 'fs';
|
|||||||
* @param {Object} context - Context object containing session and reportProgress
|
* @param {Object} context - Context object containing session and reportProgress
|
||||||
* @returns {Promise<Object>} - Task expansion result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
|
* @returns {Promise<Object>} - Task expansion result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
|
||||||
*/
|
*/
|
||||||
export async function expandTaskDirect(args, log, context = {}) {
|
export async function expandTaskDirect(args, log, { session }) {
|
||||||
const { session } = context;
|
|
||||||
|
|
||||||
// Log session root data for debugging
|
// Log session root data for debugging
|
||||||
log.info(`Session data in expandTaskDirect: ${JSON.stringify({
|
log.info(
|
||||||
|
`Session data in expandTaskDirect: ${JSON.stringify({
|
||||||
hasSession: !!session,
|
hasSession: !!session,
|
||||||
sessionKeys: session ? Object.keys(session) : [],
|
sessionKeys: session ? Object.keys(session) : [],
|
||||||
roots: session?.roots,
|
roots: session?.roots,
|
||||||
rootsStr: JSON.stringify(session?.roots)
|
rootsStr: JSON.stringify(session?.roots)
|
||||||
})}`);
|
})}`
|
||||||
|
);
|
||||||
|
|
||||||
let tasksPath;
|
let tasksPath;
|
||||||
try {
|
try {
|
||||||
// If a direct file path is provided, use it directly
|
// If a direct file path is provided, use it directly
|
||||||
if (args.file && fs.existsSync(args.file)) {
|
if (args.file && fs.existsSync(args.file)) {
|
||||||
log.info(`[expandTaskDirect] Using explicitly provided tasks file: ${args.file}`);
|
log.info(
|
||||||
|
`[expandTaskDirect] Using explicitly provided tasks file: ${args.file}`
|
||||||
|
);
|
||||||
tasksPath = args.file;
|
tasksPath = args.file;
|
||||||
} else {
|
} else {
|
||||||
// Find the tasks path through standard logic
|
// 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`);
|
log.info(
|
||||||
tasksPath = findTasksJsonPath(args, log);
|
`[expandTaskDirect] No direct file path provided or file not found at ${args.file}, searching using findTasksJsonPath`
|
||||||
|
);
|
||||||
|
tasksPath = findTasksJsonPath(args, log, session);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`[expandTaskDirect] Error during tasksPath determination: ${error.message}`);
|
log.error(
|
||||||
|
`[expandTaskDirect] Error during tasksPath determination: ${error.message}`
|
||||||
|
);
|
||||||
|
|
||||||
// Include session roots information in error
|
// Include session roots information in error
|
||||||
const sessionRootsInfo = session ?
|
const sessionRootsInfo = session
|
||||||
`\nSession.roots: ${JSON.stringify(session.roots)}\n` +
|
? `\nSession.roots: ${JSON.stringify(session.roots)}\n` +
|
||||||
`Current Working Directory: ${process.cwd()}\n` +
|
`Current Working Directory: ${process.cwd()}\n` +
|
||||||
`Args.projectRoot: ${args.projectRoot}\n` +
|
`Args.projectRoot: ${args.projectRoot}\n` +
|
||||||
`Args.file: ${args.file}\n` :
|
`Args.file: ${args.file}\n`
|
||||||
'\nSession object not available';
|
: '\nSession object not available';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -102,15 +117,21 @@ export async function expandTaskDirect(args, log, context = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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
|
// Read tasks data
|
||||||
log.info(`[expandTaskDirect] Attempting to read JSON from: ${tasksPath}`);
|
log.info(`[expandTaskDirect] Attempting to read JSON from: ${tasksPath}`);
|
||||||
const data = readJSON(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) {
|
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 {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: {
|
error: {
|
||||||
@@ -123,7 +144,7 @@ export async function expandTaskDirect(args, log, context = {}) {
|
|||||||
|
|
||||||
// Find the specific task
|
// Find the specific task
|
||||||
log.info(`[expandTaskDirect] Searching for task ID ${taskId} in data`);
|
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'}`);
|
log.info(`[expandTaskDirect] Task found: ${task ? 'Yes' : 'No'}`);
|
||||||
|
|
||||||
if (!task) {
|
if (!task) {
|
||||||
@@ -204,14 +225,17 @@ export async function expandTaskDirect(args, log, context = {}) {
|
|||||||
|
|
||||||
// Read the updated data
|
// Read the updated data
|
||||||
const updatedData = readJSON(tasksPath);
|
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
|
// Calculate how many subtasks were added
|
||||||
const subtasksAdded = updatedTask.subtasks ?
|
const subtasksAdded = updatedTask.subtasks
|
||||||
updatedTask.subtasks.length - subtasksCountBefore : 0;
|
? updatedTask.subtasks.length - subtasksCountBefore
|
||||||
|
: 0;
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
log.info(`Successfully expanded task ${taskId} with ${subtasksAdded} new subtasks`);
|
log.info(
|
||||||
|
`Successfully expanded task ${taskId} with ${subtasksAdded} new subtasks`
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -4,7 +4,10 @@
|
|||||||
|
|
||||||
import { fixDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js';
|
import { fixDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
import {
|
||||||
|
enableSilentMode,
|
||||||
|
disableSilentMode
|
||||||
|
} from '../../../../scripts/modules/utils.js';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,12 +18,12 @@ import fs from 'fs';
|
|||||||
* @param {Object} log - Logger object
|
* @param {Object} log - Logger object
|
||||||
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
||||||
*/
|
*/
|
||||||
export async function fixDependenciesDirect(args, log) {
|
export async function fixDependenciesDirect(args, log, { session }) {
|
||||||
try {
|
try {
|
||||||
log.info(`Fixing invalid dependencies in tasks...`);
|
log.info(`Fixing invalid dependencies in tasks...`);
|
||||||
|
|
||||||
// Find the tasks.json path
|
// Find the tasks.json path
|
||||||
const tasksPath = findTasksJsonPath(args, log);
|
const tasksPath = findTasksJsonPath(args, log, session);
|
||||||
|
|
||||||
// Verify the file exists
|
// Verify the file exists
|
||||||
if (!fs.existsSync(tasksPath)) {
|
if (!fs.existsSync(tasksPath)) {
|
||||||
|
|||||||
@@ -4,7 +4,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { generateTaskFiles } from '../../../../scripts/modules/task-manager.js';
|
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 { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
@@ -15,14 +18,14 @@ import path from 'path';
|
|||||||
* @param {Object} log - Logger object.
|
* @param {Object} log - Logger object.
|
||||||
* @returns {Promise<Object>} - Result object with success status and data/error information.
|
* @returns {Promise<Object>} - Result object with success status and data/error information.
|
||||||
*/
|
*/
|
||||||
export async function generateTaskFilesDirect(args, log) {
|
export async function generateTaskFilesDirect(args, log, { session }) {
|
||||||
try {
|
try {
|
||||||
log.info(`Generating task files with args: ${JSON.stringify(args)}`);
|
log.info(`Generating task files with args: ${JSON.stringify(args)}`);
|
||||||
|
|
||||||
// Get tasks file path
|
// Get tasks file path
|
||||||
let tasksPath;
|
let tasksPath;
|
||||||
try {
|
try {
|
||||||
tasksPath = findTasksJsonPath(args, log);
|
tasksPath = findTasksJsonPath(args, log, session);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Error finding tasks file: ${error.message}`);
|
log.error(`Error finding tasks file: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
@@ -69,7 +72,8 @@ export async function generateTaskFilesDirect(args, log) {
|
|||||||
message: `Successfully generated task files`,
|
message: `Successfully generated task files`,
|
||||||
tasksPath,
|
tasksPath,
|
||||||
outputDir,
|
outputDir,
|
||||||
taskFiles: 'Individual task files have been generated in the output directory'
|
taskFiles:
|
||||||
|
'Individual task files have been generated in the output directory'
|
||||||
},
|
},
|
||||||
fromCache: false // This operation always modifies state and should never be cached
|
fromCache: false // This operation always modifies state and should never be cached
|
||||||
};
|
};
|
||||||
@@ -80,7 +84,10 @@ export async function generateTaskFilesDirect(args, log) {
|
|||||||
log.error(`Error generating task files: ${error.message}`);
|
log.error(`Error generating task files: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
success: false,
|
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
|
fromCache: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,138 @@
|
|||||||
|
import path from 'path';
|
||||||
|
import { initializeProject, log as initLog } 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 project details and options (projectName, projectDescription, yes, etc.)
|
||||||
|
* @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, { session }) {
|
||||||
|
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 = {
|
||||||
|
name: args.projectName,
|
||||||
|
description: args.projectDescription,
|
||||||
|
version: args.projectVersion,
|
||||||
|
author: args.authorName,
|
||||||
|
skipInstall: args.skipInstall,
|
||||||
|
aliases: args.addAliases,
|
||||||
|
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 };
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,10 @@
|
|||||||
import { listTasks } from '../../../../scripts/modules/task-manager.js';
|
import { listTasks } from '../../../../scripts/modules/task-manager.js';
|
||||||
import { getCachedOrExecute } from '../../tools/utils.js';
|
import { getCachedOrExecute } from '../../tools/utils.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
import {
|
||||||
|
enableSilentMode,
|
||||||
|
disableSilentMode
|
||||||
|
} from '../../../../scripts/modules/utils.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Direct function wrapper for listTasks with error handling and caching.
|
* Direct function wrapper for listTasks with error handling and caching.
|
||||||
@@ -15,20 +18,28 @@ import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules
|
|||||||
* @param {Object} log - Logger object.
|
* @param {Object} log - Logger object.
|
||||||
* @returns {Promise<Object>} - Task list result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }.
|
* @returns {Promise<Object>} - Task list result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }.
|
||||||
*/
|
*/
|
||||||
export async function listTasksDirect(args, log) {
|
export async function listTasksDirect(args, log, { session }) {
|
||||||
let tasksPath;
|
let tasksPath;
|
||||||
try {
|
try {
|
||||||
// Find the tasks path first - needed for cache key and execution
|
// Find the tasks path first - needed for cache key and execution
|
||||||
tasksPath = findTasksJsonPath(args, log);
|
tasksPath = findTasksJsonPath(args, log, session);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.code === 'TASKS_FILE_NOT_FOUND') {
|
if (error.code === 'TASKS_FILE_NOT_FOUND') {
|
||||||
log.error(`Tasks file not found: ${error.message}`);
|
log.error(`Tasks file not found: ${error.message}`);
|
||||||
// Return the error structure expected by the calling tool/handler
|
// Return the error structure expected by the calling tool/handler
|
||||||
return { success: false, error: { code: error.code, message: error.message }, fromCache: false };
|
return {
|
||||||
|
success: false,
|
||||||
|
error: { code: error.code, message: error.message },
|
||||||
|
fromCache: false
|
||||||
|
};
|
||||||
}
|
}
|
||||||
log.error(`Unexpected error finding tasks file: ${error.message}`);
|
log.error(`Unexpected error finding tasks file: ${error.message}`);
|
||||||
// Re-throw for outer catch or return structured error
|
// Re-throw for outer catch or return structured error
|
||||||
return { success: false, error: { code: 'FIND_TASKS_PATH_ERROR', message: error.message }, fromCache: false };
|
return {
|
||||||
|
success: false,
|
||||||
|
error: { code: 'FIND_TASKS_PATH_ERROR', message: error.message },
|
||||||
|
fromCache: false
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate cache key *after* finding tasksPath
|
// Generate cache key *after* finding tasksPath
|
||||||
@@ -42,26 +53,46 @@ export async function listTasksDirect(args, log) {
|
|||||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||||
enableSilentMode();
|
enableSilentMode();
|
||||||
|
|
||||||
log.info(`Executing core listTasks function for path: ${tasksPath}, filter: ${statusFilter}, subtasks: ${withSubtasks}`);
|
log.info(
|
||||||
const resultData = listTasks(tasksPath, statusFilter, withSubtasks, 'json');
|
`Executing core listTasks function for path: ${tasksPath}, filter: ${statusFilter}, subtasks: ${withSubtasks}`
|
||||||
|
);
|
||||||
|
const resultData = listTasks(
|
||||||
|
tasksPath,
|
||||||
|
statusFilter,
|
||||||
|
withSubtasks,
|
||||||
|
'json'
|
||||||
|
);
|
||||||
|
|
||||||
if (!resultData || !resultData.tasks) {
|
if (!resultData || !resultData.tasks) {
|
||||||
log.error('Invalid or empty response from listTasks core function');
|
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
|
// Restore normal logging
|
||||||
disableSilentMode();
|
disableSilentMode();
|
||||||
|
|
||||||
return { success: true, data: resultData };
|
return { success: true, data: resultData };
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Make sure to restore normal logging even if there's an error
|
// Make sure to restore normal logging even if there's an error
|
||||||
disableSilentMode();
|
disableSilentMode();
|
||||||
|
|
||||||
log.error(`Core listTasks function failed: ${error.message}`);
|
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'
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -76,8 +107,14 @@ export async function listTasksDirect(args, log) {
|
|||||||
return result; // Returns { success, data/error, fromCache }
|
return result; // Returns { success, data/error, fromCache }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Catch unexpected errors from getCachedOrExecute itself (though unlikely)
|
// 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);
|
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
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,10 @@ import { findNextTask } from '../../../../scripts/modules/task-manager.js';
|
|||||||
import { readJSON } from '../../../../scripts/modules/utils.js';
|
import { readJSON } from '../../../../scripts/modules/utils.js';
|
||||||
import { getCachedOrExecute } from '../../tools/utils.js';
|
import { getCachedOrExecute } from '../../tools/utils.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/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.
|
* Direct function wrapper for finding the next task to work on with error handling and caching.
|
||||||
@@ -16,11 +19,11 @@ import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules
|
|||||||
* @param {Object} log - Logger object
|
* @param {Object} log - Logger object
|
||||||
* @returns {Promise<Object>} - Next task result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
|
* @returns {Promise<Object>} - Next task result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
|
||||||
*/
|
*/
|
||||||
export async function nextTaskDirect(args, log) {
|
export async function nextTaskDirect(args, log, { session }) {
|
||||||
let tasksPath;
|
let tasksPath;
|
||||||
try {
|
try {
|
||||||
// Find the tasks path first - needed for cache key and execution
|
// Find the tasks path first - needed for cache key and execution
|
||||||
tasksPath = findTasksJsonPath(args, log);
|
tasksPath = findTasksJsonPath(args, log, session);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Tasks file not found: ${error.message}`);
|
log.error(`Tasks file not found: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
@@ -60,11 +63,14 @@ export async function nextTaskDirect(args, log) {
|
|||||||
const nextTask = findNextTask(data.tasks);
|
const nextTask = findNextTask(data.tasks);
|
||||||
|
|
||||||
if (!nextTask) {
|
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 {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data: {
|
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,
|
nextTask: null,
|
||||||
allTasks: data.tasks
|
allTasks: data.tasks
|
||||||
}
|
}
|
||||||
@@ -75,7 +81,9 @@ export async function nextTaskDirect(args, log) {
|
|||||||
disableSilentMode();
|
disableSilentMode();
|
||||||
|
|
||||||
// Return the next task data with the full tasks array for reference
|
// 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 {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data: {
|
data: {
|
||||||
@@ -109,7 +117,9 @@ export async function nextTaskDirect(args, log) {
|
|||||||
return result; // Returns { success, data/error, fromCache }
|
return result; // Returns { success, data/error, fromCache }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Catch unexpected errors from getCachedOrExecute itself
|
// 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 {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: {
|
error: {
|
||||||
|
|||||||
@@ -5,10 +5,17 @@
|
|||||||
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import os from 'os'; // Import os module for home directory check
|
||||||
import { parsePRD } from '../../../../scripts/modules/task-manager.js';
|
import { parsePRD } from '../../../../scripts/modules/task-manager.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
import {
|
||||||
import { getAnthropicClientForMCP, getModelConfig } from '../utils/ai-client-utils.js';
|
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.
|
* Direct function wrapper for parsing PRD documents and generating tasks.
|
||||||
@@ -40,9 +47,10 @@ export async function parsePRDDirect(args, log, context = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parameter validation and path resolution
|
// --- Parameter validation and path resolution ---
|
||||||
if (!args.input) {
|
if (!args.input) {
|
||||||
const errorMessage = 'No input file specified. Please provide an input PRD document path.';
|
const errorMessage =
|
||||||
|
'No input file specified. Please provide an input PRD document path.';
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -51,26 +59,75 @@ export async function parsePRDDirect(args, log, context = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve input path (relative to project root if provided)
|
// Validate projectRoot
|
||||||
const projectRoot = args.projectRoot || process.cwd();
|
if (!args.projectRoot) {
|
||||||
const inputPath = path.isAbsolute(args.input) ? args.input : path.resolve(projectRoot, args.input);
|
const errorMessage = 'Project root is required but was not provided';
|
||||||
|
log.error(errorMessage);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: { code: 'MISSING_PROJECT_ROOT', message: errorMessage },
|
||||||
|
fromCache: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const homeDir = os.homedir();
|
||||||
|
// Disallow invalid projectRoot values
|
||||||
|
if (args.projectRoot === '/' || args.projectRoot === homeDir) {
|
||||||
|
const errorMessage = `Invalid project root: ${args.projectRoot}. Cannot use root or home directory.`;
|
||||||
|
log.error(errorMessage);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: { code: 'INVALID_PROJECT_ROOT', message: errorMessage },
|
||||||
|
fromCache: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve input path (relative to validated project root)
|
||||||
|
const projectRoot = args.projectRoot;
|
||||||
|
log.info(`Using validated project root: ${projectRoot}`);
|
||||||
|
|
||||||
|
// Make sure the project root directory exists
|
||||||
|
if (!fs.existsSync(projectRoot)) {
|
||||||
|
const errorMessage = `Project root directory does not exist: ${projectRoot}`;
|
||||||
|
log.error(errorMessage);
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
error: { code: 'PROJECT_ROOT_NOT_FOUND', message: errorMessage },
|
||||||
|
fromCache: false
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve input path relative to validated project root
|
||||||
|
const inputPath = path.isAbsolute(args.input)
|
||||||
|
? args.input
|
||||||
|
: path.resolve(projectRoot, args.input);
|
||||||
|
|
||||||
|
log.info(`Resolved input path: ${inputPath}`);
|
||||||
|
|
||||||
// Determine output path
|
// Determine output path
|
||||||
let outputPath;
|
let outputPath;
|
||||||
if (args.output) {
|
if (args.output) {
|
||||||
outputPath = path.isAbsolute(args.output) ? args.output : path.resolve(projectRoot, args.output);
|
outputPath = path.isAbsolute(args.output)
|
||||||
|
? args.output
|
||||||
|
: path.resolve(projectRoot, args.output);
|
||||||
} else {
|
} else {
|
||||||
// Default to tasks/tasks.json in the project root
|
// Default to tasks/tasks.json in the project root
|
||||||
outputPath = path.resolve(projectRoot, 'tasks', 'tasks.json');
|
outputPath = path.resolve(projectRoot, 'tasks', 'tasks.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.info(`Resolved output path: ${outputPath}`);
|
||||||
|
|
||||||
// Verify input file exists
|
// Verify input file exists
|
||||||
if (!fs.existsSync(inputPath)) {
|
if (!fs.existsSync(inputPath)) {
|
||||||
const errorMessage = `Input file not found: ${inputPath}`;
|
const errorMessage = `Input file not found: ${inputPath}`;
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: { code: 'INPUT_FILE_NOT_FOUND', message: errorMessage },
|
error: {
|
||||||
|
code: 'INPUT_FILE_NOT_FOUND',
|
||||||
|
message: errorMessage,
|
||||||
|
details: `Checked path: ${inputPath}\nProject root: ${projectRoot}\nInput argument: ${args.input}`
|
||||||
|
},
|
||||||
fromCache: false
|
fromCache: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -78,14 +135,19 @@ export async function parsePRDDirect(args, log, context = {}) {
|
|||||||
// Parse number of tasks - handle both string and number values
|
// Parse number of tasks - handle both string and number values
|
||||||
let numTasks = 10; // Default
|
let numTasks = 10; // Default
|
||||||
if (args.numTasks) {
|
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)) {
|
if (isNaN(numTasks)) {
|
||||||
numTasks = 10; // Fallback to default if parsing fails
|
numTasks = 10; // Fallback to default if parsing fails
|
||||||
log.warn(`Invalid numTasks value: ${args.numTasks}. Using default: 10`);
|
log.warn(`Invalid numTasks value: ${args.numTasks}. Using default: 10`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info(`Preparing to parse PRD from ${inputPath} and output to ${outputPath} with ${numTasks} tasks`);
|
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
|
// Create the logger wrapper for proper logging in the core function
|
||||||
const logWrapper = {
|
const logWrapper = {
|
||||||
@@ -102,17 +164,33 @@ export async function parsePRDDirect(args, log, context = {}) {
|
|||||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||||
enableSilentMode();
|
enableSilentMode();
|
||||||
try {
|
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
|
// Execute core parsePRD function with AI client
|
||||||
await parsePRD(inputPath, outputPath, numTasks, {
|
await parsePRD(
|
||||||
|
inputPath,
|
||||||
|
outputPath,
|
||||||
|
numTasks,
|
||||||
|
{
|
||||||
mcpLog: logWrapper,
|
mcpLog: logWrapper,
|
||||||
session
|
session
|
||||||
}, aiClient, modelConfig);
|
},
|
||||||
|
aiClient,
|
||||||
|
modelConfig
|
||||||
|
);
|
||||||
|
|
||||||
// Since parsePRD doesn't return a value but writes to a file, we'll read the result
|
// Since parsePRD doesn't return a value but writes to a file, we'll read the result
|
||||||
// to return it to the caller
|
// to return it to the caller
|
||||||
if (fs.existsSync(outputPath)) {
|
if (fs.existsSync(outputPath)) {
|
||||||
const tasksData = JSON.parse(fs.readFileSync(outputPath, 'utf8'));
|
const tasksData = JSON.parse(fs.readFileSync(outputPath, 'utf8'));
|
||||||
log.info(`Successfully parsed PRD and generated ${tasksData.tasks?.length || 0} tasks`);
|
log.info(
|
||||||
|
`Successfully parsed PRD and generated ${tasksData.tasks?.length || 0} tasks`
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
@@ -143,7 +221,10 @@ export async function parsePRDDirect(args, log, context = {}) {
|
|||||||
log.error(`Error parsing PRD: ${error.message}`);
|
log.error(`Error parsing PRD: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
success: false,
|
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
|
fromCache: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,10 @@
|
|||||||
|
|
||||||
import { removeDependency } from '../../../../scripts/modules/dependency-manager.js';
|
import { removeDependency } from '../../../../scripts/modules/dependency-manager.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
import {
|
||||||
|
enableSilentMode,
|
||||||
|
disableSilentMode
|
||||||
|
} from '../../../../scripts/modules/utils.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a dependency from a task
|
* Remove a dependency from a task
|
||||||
@@ -16,7 +19,7 @@ import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules
|
|||||||
* @param {Object} log - Logger object
|
* @param {Object} log - Logger object
|
||||||
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
||||||
*/
|
*/
|
||||||
export async function removeDependencyDirect(args, log) {
|
export async function removeDependencyDirect(args, log, { session }) {
|
||||||
try {
|
try {
|
||||||
log.info(`Removing dependency with args: ${JSON.stringify(args)}`);
|
log.info(`Removing dependency with args: ${JSON.stringify(args)}`);
|
||||||
|
|
||||||
@@ -42,13 +45,21 @@ export async function removeDependencyDirect(args, log) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the tasks.json path
|
// Find the tasks.json path
|
||||||
const tasksPath = findTasksJsonPath(args, log);
|
const tasksPath = findTasksJsonPath(args, log, session);
|
||||||
|
|
||||||
// Format IDs for the core function
|
// Format IDs for the core function
|
||||||
const taskId = args.id.includes && args.id.includes('.') ? args.id : parseInt(args.id, 10);
|
const taskId =
|
||||||
const dependencyId = args.dependsOn.includes && args.dependsOn.includes('.') ? args.dependsOn : parseInt(args.dependsOn, 10);
|
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
|
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||||
enableSilentMode();
|
enableSilentMode();
|
||||||
|
|||||||
@@ -4,7 +4,10 @@
|
|||||||
|
|
||||||
import { removeSubtask } from '../../../../scripts/modules/task-manager.js';
|
import { removeSubtask } from '../../../../scripts/modules/task-manager.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
import {
|
||||||
|
enableSilentMode,
|
||||||
|
disableSilentMode
|
||||||
|
} from '../../../../scripts/modules/utils.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove a subtask from its parent task
|
* Remove a subtask from its parent task
|
||||||
@@ -17,7 +20,7 @@ import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules
|
|||||||
* @param {Object} log - Logger object
|
* @param {Object} log - Logger object
|
||||||
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
||||||
*/
|
*/
|
||||||
export async function removeSubtaskDirect(args, log) {
|
export async function removeSubtaskDirect(args, log, { session }) {
|
||||||
try {
|
try {
|
||||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||||
enableSilentMode();
|
enableSilentMode();
|
||||||
@@ -29,7 +32,8 @@ export async function removeSubtaskDirect(args, log) {
|
|||||||
success: false,
|
success: false,
|
||||||
error: {
|
error: {
|
||||||
code: 'INPUT_VALIDATION_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"'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -46,7 +50,7 @@ export async function removeSubtaskDirect(args, log) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the tasks.json path
|
// Find the tasks.json path
|
||||||
const tasksPath = findTasksJsonPath(args, log);
|
const tasksPath = findTasksJsonPath(args, log, session);
|
||||||
|
|
||||||
// Convert convertToTask to a boolean
|
// Convert convertToTask to a boolean
|
||||||
const convertToTask = args.convert === true;
|
const convertToTask = args.convert === true;
|
||||||
@@ -54,9 +58,16 @@ export async function removeSubtaskDirect(args, log) {
|
|||||||
// Determine if we should generate files
|
// Determine if we should generate files
|
||||||
const generateFiles = !args.skipGenerate;
|
const generateFiles = !args.skipGenerate;
|
||||||
|
|
||||||
log.info(`Removing subtask ${args.id} (convertToTask: ${convertToTask}, generateFiles: ${generateFiles})`);
|
log.info(
|
||||||
|
`Removing subtask ${args.id} (convertToTask: ${convertToTask}, generateFiles: ${generateFiles})`
|
||||||
|
);
|
||||||
|
|
||||||
const result = await removeSubtask(tasksPath, args.id, convertToTask, generateFiles);
|
const result = await removeSubtask(
|
||||||
|
tasksPath,
|
||||||
|
args.id,
|
||||||
|
convertToTask,
|
||||||
|
generateFiles
|
||||||
|
);
|
||||||
|
|
||||||
// Restore normal logging
|
// Restore normal logging
|
||||||
disableSilentMode();
|
disableSilentMode();
|
||||||
|
|||||||
@@ -4,7 +4,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { removeTask } from '../../../../scripts/modules/task-manager.js';
|
import { removeTask } 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 { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,12 +17,12 @@ import { findTasksJsonPath } from '../utils/path-utils.js';
|
|||||||
* @param {Object} log - Logger object
|
* @param {Object} log - Logger object
|
||||||
* @returns {Promise<Object>} - Remove task result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: false }
|
* @returns {Promise<Object>} - Remove task result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: false }
|
||||||
*/
|
*/
|
||||||
export async function removeTaskDirect(args, log) {
|
export async function removeTaskDirect(args, log, { session }) {
|
||||||
try {
|
try {
|
||||||
// Find the tasks path first
|
// Find the tasks path first
|
||||||
let tasksPath;
|
let tasksPath;
|
||||||
try {
|
try {
|
||||||
tasksPath = findTasksJsonPath(args, log);
|
tasksPath = findTasksJsonPath(args, log, session);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Tasks file not found: ${error.message}`);
|
log.error(`Tasks file not found: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -5,7 +5,11 @@
|
|||||||
|
|
||||||
import { setTaskStatus } from '../../../../scripts/modules/task-manager.js';
|
import { setTaskStatus } from '../../../../scripts/modules/task-manager.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { enableSilentMode, disableSilentMode, isSilentMode } from '../../../../scripts/modules/utils.js';
|
import {
|
||||||
|
enableSilentMode,
|
||||||
|
disableSilentMode,
|
||||||
|
isSilentMode
|
||||||
|
} from '../../../../scripts/modules/utils.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Direct function wrapper for setTaskStatus with error handling.
|
* Direct function wrapper for setTaskStatus with error handling.
|
||||||
@@ -14,13 +18,14 @@ import { enableSilentMode, disableSilentMode, isSilentMode } from '../../../../s
|
|||||||
* @param {Object} log - Logger object.
|
* @param {Object} log - Logger object.
|
||||||
* @returns {Promise<Object>} - Result object with success status and data/error information.
|
* @returns {Promise<Object>} - Result object with success status and data/error information.
|
||||||
*/
|
*/
|
||||||
export async function setTaskStatusDirect(args, log) {
|
export async function setTaskStatusDirect(args, log, { session }) {
|
||||||
try {
|
try {
|
||||||
log.info(`Setting task status with args: ${JSON.stringify(args)}`);
|
log.info(`Setting task status with args: ${JSON.stringify(args)}`);
|
||||||
|
|
||||||
// Check required parameters
|
// Check required parameters
|
||||||
if (!args.id) {
|
if (!args.id) {
|
||||||
const errorMessage = 'No task ID specified. Please provide a task ID to update.';
|
const errorMessage =
|
||||||
|
'No task ID specified. Please provide a task ID to update.';
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -30,7 +35,8 @@ export async function setTaskStatusDirect(args, log) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!args.status) {
|
if (!args.status) {
|
||||||
const errorMessage = 'No status specified. Please provide a new status value.';
|
const errorMessage =
|
||||||
|
'No status specified. Please provide a new status value.';
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -43,7 +49,7 @@ export async function setTaskStatusDirect(args, log) {
|
|||||||
let tasksPath;
|
let tasksPath;
|
||||||
try {
|
try {
|
||||||
// The enhanced findTasksJsonPath will now search in parent directories if needed
|
// The enhanced findTasksJsonPath will now search in parent directories if needed
|
||||||
tasksPath = findTasksJsonPath(args, log);
|
tasksPath = findTasksJsonPath(args, log, session);
|
||||||
log.info(`Found tasks file at: ${tasksPath}`);
|
log.info(`Found tasks file at: ${tasksPath}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Error finding tasks file: ${error.message}`);
|
log.error(`Error finding tasks file: ${error.message}`);
|
||||||
@@ -87,7 +93,10 @@ export async function setTaskStatusDirect(args, log) {
|
|||||||
log.error(`Error setting task status: ${error.message}`);
|
log.error(`Error setting task status: ${error.message}`);
|
||||||
result = {
|
result = {
|
||||||
success: false,
|
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
|
fromCache: false
|
||||||
};
|
};
|
||||||
} finally {
|
} finally {
|
||||||
@@ -105,7 +114,10 @@ export async function setTaskStatusDirect(args, log) {
|
|||||||
log.error(`Error setting task status: ${error.message}`);
|
log.error(`Error setting task status: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: { code: 'SET_STATUS_ERROR', message: error.message || 'Unknown error setting task status' },
|
error: {
|
||||||
|
code: 'SET_STATUS_ERROR',
|
||||||
|
message: error.message || 'Unknown error setting task status'
|
||||||
|
},
|
||||||
fromCache: false
|
fromCache: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,10 @@ import { findTaskById } from '../../../../scripts/modules/utils.js';
|
|||||||
import { readJSON } from '../../../../scripts/modules/utils.js';
|
import { readJSON } from '../../../../scripts/modules/utils.js';
|
||||||
import { getCachedOrExecute } from '../../tools/utils.js';
|
import { getCachedOrExecute } from '../../tools/utils.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
import {
|
||||||
|
enableSilentMode,
|
||||||
|
disableSilentMode
|
||||||
|
} from '../../../../scripts/modules/utils.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Direct function wrapper for showing task details with error handling and caching.
|
* Direct function wrapper for showing task details with error handling and caching.
|
||||||
@@ -16,11 +19,11 @@ import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules
|
|||||||
* @param {Object} log - Logger object
|
* @param {Object} log - Logger object
|
||||||
* @returns {Promise<Object>} - Task details result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
|
* @returns {Promise<Object>} - Task details result { success: boolean, data?: any, error?: { code: string, message: string }, fromCache: boolean }
|
||||||
*/
|
*/
|
||||||
export async function showTaskDirect(args, log) {
|
export async function showTaskDirect(args, log, { session }) {
|
||||||
let tasksPath;
|
let tasksPath;
|
||||||
try {
|
try {
|
||||||
// Find the tasks path first - needed for cache key and execution
|
// Find the tasks path first - needed for cache key and execution
|
||||||
tasksPath = findTasksJsonPath(args, log);
|
tasksPath = findTasksJsonPath(args, log, session);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Tasks file not found: ${error.message}`);
|
log.error(`Tasks file not found: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
@@ -123,7 +126,9 @@ export async function showTaskDirect(args, log) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Catch unexpected errors from getCachedOrExecute itself
|
// Catch unexpected errors from getCachedOrExecute itself
|
||||||
disableSilentMode();
|
disableSilentMode();
|
||||||
log.error(`Unexpected error during getCachedOrExecute for showTask: ${error.message}`);
|
log.error(
|
||||||
|
`Unexpected error during getCachedOrExecute for showTask: ${error.message}`
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: {
|
error: {
|
||||||
|
|||||||
@@ -4,9 +4,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { updateSubtaskById } from '../../../../scripts/modules/task-manager.js';
|
import { updateSubtaskById } 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 { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { getAnthropicClientForMCP, getPerplexityClientForMCP } from '../utils/ai-client-utils.js';
|
import {
|
||||||
|
getAnthropicClientForMCP,
|
||||||
|
getPerplexityClientForMCP
|
||||||
|
} from '../utils/ai-client-utils.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Direct function wrapper for updateSubtaskById with error handling.
|
* Direct function wrapper for updateSubtaskById with error handling.
|
||||||
@@ -16,15 +22,14 @@ import { getAnthropicClientForMCP, getPerplexityClientForMCP } from '../utils/ai
|
|||||||
* @param {Object} context - Context object containing session data.
|
* @param {Object} context - Context object containing session data.
|
||||||
* @returns {Promise<Object>} - Result object with success status and data/error information.
|
* @returns {Promise<Object>} - Result object with success status and data/error information.
|
||||||
*/
|
*/
|
||||||
export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
export async function updateSubtaskByIdDirect(args, log, { session }) {
|
||||||
const { session } = context; // Only extract session, not reportProgress
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.info(`Updating subtask with args: ${JSON.stringify(args)}`);
|
log.info(`Updating subtask with args: ${JSON.stringify(args)}`);
|
||||||
|
|
||||||
// Check required parameters
|
// Check required parameters
|
||||||
if (!args.id) {
|
if (!args.id) {
|
||||||
const errorMessage = 'No subtask ID specified. Please provide a subtask ID to update.';
|
const errorMessage =
|
||||||
|
'No subtask ID specified. Please provide a subtask ID to update.';
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -34,7 +39,8 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!args.prompt) {
|
if (!args.prompt) {
|
||||||
const errorMessage = 'No prompt specified. Please provide a prompt with information to add to the subtask.';
|
const errorMessage =
|
||||||
|
'No prompt specified. Please provide a prompt with information to add to the subtask.';
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -69,7 +75,7 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
|||||||
// Get tasks file path
|
// Get tasks file path
|
||||||
let tasksPath;
|
let tasksPath;
|
||||||
try {
|
try {
|
||||||
tasksPath = findTasksJsonPath(args, log);
|
tasksPath = findTasksJsonPath(args, log, session);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Error finding tasks file: ${error.message}`);
|
log.error(`Error finding tasks file: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
@@ -82,7 +88,9 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
|||||||
// Get research flag
|
// Get research flag
|
||||||
const useResearch = args.research === true;
|
const useResearch = args.research === true;
|
||||||
|
|
||||||
log.info(`Updating subtask with ID ${subtaskIdStr} with prompt "${args.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
|
// Initialize the appropriate AI client based on research flag
|
||||||
try {
|
try {
|
||||||
@@ -97,7 +105,10 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
|||||||
log.error(`AI client initialization error: ${error.message}`);
|
log.error(`AI client initialization error: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
success: false,
|
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
|
fromCache: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -118,10 +129,16 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
|||||||
|
|
||||||
// Execute core updateSubtaskById function
|
// Execute core updateSubtaskById function
|
||||||
// Pass both session and logWrapper as mcpLog to ensure outputFormat is 'json'
|
// Pass both session and logWrapper as mcpLog to ensure outputFormat is 'json'
|
||||||
const updatedSubtask = await updateSubtaskById(tasksPath, subtaskIdStr, args.prompt, useResearch, {
|
const updatedSubtask = await updateSubtaskById(
|
||||||
|
tasksPath,
|
||||||
|
subtaskIdStr,
|
||||||
|
args.prompt,
|
||||||
|
useResearch,
|
||||||
|
{
|
||||||
session,
|
session,
|
||||||
mcpLog: logWrapper
|
mcpLog: logWrapper
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// Restore normal logging
|
// Restore normal logging
|
||||||
disableSilentMode();
|
disableSilentMode();
|
||||||
@@ -132,7 +149,8 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
|||||||
success: false,
|
success: false,
|
||||||
error: {
|
error: {
|
||||||
code: 'SUBTASK_UPDATE_FAILED',
|
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
|
fromCache: false
|
||||||
};
|
};
|
||||||
@@ -163,7 +181,10 @@ export async function updateSubtaskByIdDirect(args, log, context = {}) {
|
|||||||
log.error(`Error updating subtask by ID: ${error.message}`);
|
log.error(`Error updating subtask by ID: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
success: false,
|
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
|
fromCache: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,10 @@
|
|||||||
|
|
||||||
import { updateTaskById } from '../../../../scripts/modules/task-manager.js';
|
import { updateTaskById } from '../../../../scripts/modules/task-manager.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
import {
|
||||||
|
enableSilentMode,
|
||||||
|
disableSilentMode
|
||||||
|
} from '../../../../scripts/modules/utils.js';
|
||||||
import {
|
import {
|
||||||
getAnthropicClientForMCP,
|
getAnthropicClientForMCP,
|
||||||
getPerplexityClientForMCP
|
getPerplexityClientForMCP
|
||||||
@@ -19,15 +22,14 @@ import {
|
|||||||
* @param {Object} context - Context object containing session data.
|
* @param {Object} context - Context object containing session data.
|
||||||
* @returns {Promise<Object>} - Result object with success status and data/error information.
|
* @returns {Promise<Object>} - Result object with success status and data/error information.
|
||||||
*/
|
*/
|
||||||
export async function updateTaskByIdDirect(args, log, context = {}) {
|
export async function updateTaskByIdDirect(args, log, { session }) {
|
||||||
const { session } = context; // Only extract session, not reportProgress
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.info(`Updating task with args: ${JSON.stringify(args)}`);
|
log.info(`Updating task with args: ${JSON.stringify(args)}`);
|
||||||
|
|
||||||
// Check required parameters
|
// Check required parameters
|
||||||
if (!args.id) {
|
if (!args.id) {
|
||||||
const errorMessage = 'No task ID specified. Please provide a task ID to update.';
|
const errorMessage =
|
||||||
|
'No task ID specified. Please provide a task ID to update.';
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -37,7 +39,8 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!args.prompt) {
|
if (!args.prompt) {
|
||||||
const errorMessage = 'No prompt specified. Please provide a prompt with new information for the task update.';
|
const errorMessage =
|
||||||
|
'No prompt specified. Please provide a prompt with new information for the task update.';
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -72,7 +75,7 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
|
|||||||
// Get tasks file path
|
// Get tasks file path
|
||||||
let tasksPath;
|
let tasksPath;
|
||||||
try {
|
try {
|
||||||
tasksPath = findTasksJsonPath(args, log);
|
tasksPath = findTasksJsonPath(args, log, session);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Error finding tasks file: ${error.message}`);
|
log.error(`Error finding tasks file: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
@@ -107,7 +110,9 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info(`Updating task with ID ${taskId} with prompt "${args.prompt}" and research: ${useResearch}`);
|
log.info(
|
||||||
|
`Updating task with ID ${taskId} with prompt "${args.prompt}" and research: ${useResearch}`
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||||
@@ -151,7 +156,10 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
|
|||||||
log.error(`Error updating task by ID: ${error.message}`);
|
log.error(`Error updating task by ID: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
success: false,
|
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
|
fromCache: false
|
||||||
};
|
};
|
||||||
} finally {
|
} finally {
|
||||||
@@ -165,7 +173,10 @@ export async function updateTaskByIdDirect(args, log, context = {}) {
|
|||||||
log.error(`Error updating task by ID: ${error.message}`);
|
log.error(`Error updating task by ID: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
success: false,
|
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
|
fromCache: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { updateTasks } from '../../../../scripts/modules/task-manager.js';
|
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 { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import {
|
import {
|
||||||
getAnthropicClientForMCP,
|
getAnthropicClientForMCP,
|
||||||
@@ -19,22 +22,22 @@ import {
|
|||||||
* @param {Object} context - Context object containing session data.
|
* @param {Object} context - Context object containing session data.
|
||||||
* @returns {Promise<Object>} - Result object with success status and data/error information.
|
* @returns {Promise<Object>} - Result object with success status and data/error information.
|
||||||
*/
|
*/
|
||||||
export async function updateTasksDirect(args, log, context = {}) {
|
export async function updateTasksDirect(args, log, { session }) {
|
||||||
const { session } = context; // Only extract session, not reportProgress
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log.info(`Updating tasks with args: ${JSON.stringify(args)}`);
|
log.info(`Updating tasks with args: ${JSON.stringify(args)}`);
|
||||||
|
|
||||||
// Check for the common mistake of using 'id' instead of 'from'
|
// Check for the common mistake of using 'id' instead of 'from'
|
||||||
if (args.id !== undefined && args.from === undefined) {
|
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.";
|
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);
|
log.error(errorMessage);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: {
|
error: {
|
||||||
code: 'PARAMETER_MISMATCH',
|
code: 'PARAMETER_MISMATCH',
|
||||||
message: errorMessage,
|
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
|
fromCache: false
|
||||||
};
|
};
|
||||||
@@ -42,7 +45,8 @@ export async function updateTasksDirect(args, log, context = {}) {
|
|||||||
|
|
||||||
// Check required parameters
|
// Check required parameters
|
||||||
if (!args.from) {
|
if (!args.from) {
|
||||||
const errorMessage = 'No from ID specified. Please provide a task ID to start updating from.';
|
const errorMessage =
|
||||||
|
'No from ID specified. Please provide a task ID to start updating from.';
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -52,7 +56,8 @@ export async function updateTasksDirect(args, log, context = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!args.prompt) {
|
if (!args.prompt) {
|
||||||
const errorMessage = 'No prompt specified. Please provide a prompt with new context for task updates.';
|
const errorMessage =
|
||||||
|
'No prompt specified. Please provide a prompt with new context for task updates.';
|
||||||
log.error(errorMessage);
|
log.error(errorMessage);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
@@ -81,7 +86,7 @@ export async function updateTasksDirect(args, log, context = {}) {
|
|||||||
// Get tasks file path
|
// Get tasks file path
|
||||||
let tasksPath;
|
let tasksPath;
|
||||||
try {
|
try {
|
||||||
tasksPath = findTasksJsonPath(args, log);
|
tasksPath = findTasksJsonPath(args, log, session);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Error finding tasks file: ${error.message}`);
|
log.error(`Error finding tasks file: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
@@ -116,23 +121,19 @@ export async function updateTasksDirect(args, log, context = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info(`Updating tasks from ID ${fromId} with prompt "${args.prompt}" and research: ${useResearch}`);
|
log.info(
|
||||||
|
`Updating tasks from ID ${fromId} with prompt "${args.prompt}" and research: ${useResearch}`
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Enable silent mode to prevent console logs from interfering with JSON response
|
// Enable silent mode to prevent console logs from interfering with JSON response
|
||||||
enableSilentMode();
|
enableSilentMode();
|
||||||
|
|
||||||
// Execute core updateTasks function, passing the AI client and session
|
// Execute core updateTasks function, passing the AI client and session
|
||||||
await updateTasks(
|
await updateTasks(tasksPath, fromId, args.prompt, useResearch, {
|
||||||
tasksPath,
|
|
||||||
fromId,
|
|
||||||
args.prompt,
|
|
||||||
useResearch,
|
|
||||||
{
|
|
||||||
mcpLog: log,
|
mcpLog: log,
|
||||||
session
|
session
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
// Since updateTasks doesn't return a value but modifies the tasks file,
|
// Since updateTasks doesn't return a value but modifies the tasks file,
|
||||||
// we'll return a success message
|
// we'll return a success message
|
||||||
@@ -150,7 +151,10 @@ export async function updateTasksDirect(args, log, context = {}) {
|
|||||||
log.error(`Error updating tasks: ${error.message}`);
|
log.error(`Error updating tasks: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
success: false,
|
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
|
fromCache: false
|
||||||
};
|
};
|
||||||
} finally {
|
} finally {
|
||||||
@@ -164,7 +168,10 @@ export async function updateTasksDirect(args, log, context = {}) {
|
|||||||
log.error(`Error updating tasks: ${error.message}`);
|
log.error(`Error updating tasks: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
success: false,
|
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
|
fromCache: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,10 @@
|
|||||||
|
|
||||||
import { validateDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js';
|
import { validateDependenciesCommand } from '../../../../scripts/modules/dependency-manager.js';
|
||||||
import { findTasksJsonPath } from '../utils/path-utils.js';
|
import { findTasksJsonPath } from '../utils/path-utils.js';
|
||||||
import { enableSilentMode, disableSilentMode } from '../../../../scripts/modules/utils.js';
|
import {
|
||||||
|
enableSilentMode,
|
||||||
|
disableSilentMode
|
||||||
|
} from '../../../../scripts/modules/utils.js';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,12 +18,12 @@ import fs from 'fs';
|
|||||||
* @param {Object} log - Logger object
|
* @param {Object} log - Logger object
|
||||||
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
||||||
*/
|
*/
|
||||||
export async function validateDependenciesDirect(args, log) {
|
export async function validateDependenciesDirect(args, log, { session }) {
|
||||||
try {
|
try {
|
||||||
log.info(`Validating dependencies in tasks...`);
|
log.info(`Validating dependencies in tasks...`);
|
||||||
|
|
||||||
// Find the tasks.json path
|
// Find the tasks.json path
|
||||||
const tasksPath = findTasksJsonPath(args, log);
|
const tasksPath = findTasksJsonPath(args, log, session);
|
||||||
|
|
||||||
// Verify the file exists
|
// Verify the file exists
|
||||||
if (!fs.existsSync(tasksPath)) {
|
if (!fs.existsSync(tasksPath)) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import { fixDependenciesDirect } from './direct-functions/fix-dependencies.js';
|
|||||||
import { complexityReportDirect } from './direct-functions/complexity-report.js';
|
import { complexityReportDirect } from './direct-functions/complexity-report.js';
|
||||||
import { addDependencyDirect } from './direct-functions/add-dependency.js';
|
import { addDependencyDirect } from './direct-functions/add-dependency.js';
|
||||||
import { removeTaskDirect } from './direct-functions/remove-task.js';
|
import { removeTaskDirect } from './direct-functions/remove-task.js';
|
||||||
|
import { initializeProjectDirect } from './direct-functions/initialize-project-direct.js';
|
||||||
|
|
||||||
// Re-export utility functions
|
// Re-export utility functions
|
||||||
export { findTasksJsonPath } from './utils/path-utils.js';
|
export { findTasksJsonPath } from './utils/path-utils.js';
|
||||||
@@ -92,5 +93,6 @@ export {
|
|||||||
fixDependenciesDirect,
|
fixDependenciesDirect,
|
||||||
complexityReportDirect,
|
complexityReportDirect,
|
||||||
addDependencyDirect,
|
addDependencyDirect,
|
||||||
removeTaskDirect
|
removeTaskDirect,
|
||||||
|
initializeProjectDirect
|
||||||
};
|
};
|
||||||
@@ -26,10 +26,13 @@ const DEFAULT_MODEL_CONFIG = {
|
|||||||
export function getAnthropicClientForMCP(session, log = console) {
|
export function getAnthropicClientForMCP(session, log = console) {
|
||||||
try {
|
try {
|
||||||
// Extract API key from session.env or fall back to environment variables
|
// Extract API key from session.env or fall back to environment variables
|
||||||
const apiKey = session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY;
|
const apiKey =
|
||||||
|
session?.env?.ANTHROPIC_API_KEY || process.env.ANTHROPIC_API_KEY;
|
||||||
|
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
throw new Error('ANTHROPIC_API_KEY not found in session environment or process.env');
|
throw new Error(
|
||||||
|
'ANTHROPIC_API_KEY not found in session environment or process.env'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize and return a new Anthropic client
|
// Initialize and return a new Anthropic client
|
||||||
@@ -55,10 +58,13 @@ export function getAnthropicClientForMCP(session, log = console) {
|
|||||||
export async function getPerplexityClientForMCP(session, log = console) {
|
export async function getPerplexityClientForMCP(session, log = console) {
|
||||||
try {
|
try {
|
||||||
// Extract API key from session.env or fall back to environment variables
|
// Extract API key from session.env or fall back to environment variables
|
||||||
const apiKey = session?.env?.PERPLEXITY_API_KEY || process.env.PERPLEXITY_API_KEY;
|
const apiKey =
|
||||||
|
session?.env?.PERPLEXITY_API_KEY || process.env.PERPLEXITY_API_KEY;
|
||||||
|
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
throw new Error('PERPLEXITY_API_KEY not found in session environment or process.env');
|
throw new Error(
|
||||||
|
'PERPLEXITY_API_KEY not found in session environment or process.env'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dynamically import OpenAI (it may not be used in all contexts)
|
// Dynamically import OpenAI (it may not be used in all contexts)
|
||||||
@@ -100,13 +106,19 @@ export function getModelConfig(session, defaults = DEFAULT_MODEL_CONFIG) {
|
|||||||
* @returns {Promise<Object>} Selected model info with type and client
|
* @returns {Promise<Object>} Selected model info with type and client
|
||||||
* @throws {Error} If no AI models are available
|
* @throws {Error} If no AI models are available
|
||||||
*/
|
*/
|
||||||
export async function getBestAvailableAIModel(session, options = {}, log = console) {
|
export async function getBestAvailableAIModel(
|
||||||
|
session,
|
||||||
|
options = {},
|
||||||
|
log = console
|
||||||
|
) {
|
||||||
const { requiresResearch = false, claudeOverloaded = false } = options;
|
const { requiresResearch = false, claudeOverloaded = false } = options;
|
||||||
|
|
||||||
// Test case: When research is needed but no Perplexity, use Claude
|
// 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?.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 {
|
try {
|
||||||
log.warn('Perplexity not available for research, using Claude');
|
log.warn('Perplexity not available for research, using Claude');
|
||||||
const client = getAnthropicClientForMCP(session, log);
|
const client = getAnthropicClientForMCP(session, log);
|
||||||
@@ -118,7 +130,10 @@ export async function getBestAvailableAIModel(session, options = {}, log = conso
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Regular path: Perplexity for research when available
|
// 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 {
|
try {
|
||||||
const client = await getPerplexityClientForMCP(session, log);
|
const client = await getPerplexityClientForMCP(session, log);
|
||||||
return { type: 'perplexity', client };
|
return { type: 'perplexity', client };
|
||||||
@@ -129,19 +144,29 @@ export async function getBestAvailableAIModel(session, options = {}, log = conso
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test case: Claude for overloaded scenario
|
// 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 {
|
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);
|
const client = getAnthropicClientForMCP(session, log);
|
||||||
return { type: 'claude', client };
|
return { type: 'claude', client };
|
||||||
} catch (error) {
|
} 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');
|
throw new Error('No AI models available');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default case: Use Claude when available and not overloaded
|
// 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 {
|
try {
|
||||||
const client = getAnthropicClientForMCP(session, log);
|
const client = getAnthropicClientForMCP(session, log);
|
||||||
return { type: 'claude', client };
|
return { type: 'claude', client };
|
||||||
|
|||||||
@@ -33,11 +33,19 @@ class AsyncOperationManager {
|
|||||||
this.log(operationId, 'info', `Operation added.`);
|
this.log(operationId, 'info', `Operation added.`);
|
||||||
|
|
||||||
// Start execution in the background (don't await here)
|
// Start execution in the background (don't await here)
|
||||||
this._runOperation(operationId, operationFn, args, context).catch(err => {
|
this._runOperation(operationId, operationFn, args, context).catch((err) => {
|
||||||
// Catch unexpected errors during the async execution setup itself
|
// Catch unexpected errors during the async execution setup itself
|
||||||
this.log(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.status = 'failed';
|
||||||
operation.error = { code: 'MANAGER_EXECUTION_ERROR', message: err.message };
|
operation.error = {
|
||||||
|
code: 'MANAGER_EXECUTION_ERROR',
|
||||||
|
message: err.message
|
||||||
|
};
|
||||||
operation.endTime = Date.now();
|
operation.endTime = Date.now();
|
||||||
|
|
||||||
// Move to completed operations
|
// Move to completed operations
|
||||||
@@ -67,7 +75,8 @@ class AsyncOperationManager {
|
|||||||
// The direct function needs to be adapted if it needs reportProgress
|
// The direct function needs to be adapted if it needs reportProgress
|
||||||
// We pass the original context's log, plus our wrapped reportProgress
|
// We pass the original context's log, plus our wrapped reportProgress
|
||||||
const result = await operationFn(args, operation.log, {
|
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
|
mcpLog: operation.log, // Pass log as mcpLog if direct fn expects it
|
||||||
session: operation.session
|
session: operation.session
|
||||||
});
|
});
|
||||||
@@ -75,15 +84,31 @@ class AsyncOperationManager {
|
|||||||
operation.status = result.success ? 'completed' : 'failed';
|
operation.status = result.success ? 'completed' : 'failed';
|
||||||
operation.result = result.success ? result.data : null;
|
operation.result = result.success ? result.data : null;
|
||||||
operation.error = result.success ? null : result.error;
|
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) {
|
} 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.status = 'failed';
|
||||||
operation.error = { code: 'OPERATION_EXECUTION_ERROR', message: error.message };
|
operation.error = {
|
||||||
|
code: 'OPERATION_EXECUTION_ERROR',
|
||||||
|
message: error.message
|
||||||
|
};
|
||||||
} finally {
|
} finally {
|
||||||
operation.endTime = Date.now();
|
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
|
// Move to completed operations if done or failed
|
||||||
if (operation.status === 'completed' || operation.status === 'failed') {
|
if (operation.status === 'completed' || operation.status === 'failed') {
|
||||||
@@ -108,7 +133,7 @@ class AsyncOperationManager {
|
|||||||
startTime: operation.startTime,
|
startTime: operation.startTime,
|
||||||
endTime: operation.endTime,
|
endTime: operation.endTime,
|
||||||
result: operation.result,
|
result: operation.result,
|
||||||
error: operation.error,
|
error: operation.error
|
||||||
};
|
};
|
||||||
|
|
||||||
this.completedOperations.set(operationId, completedData);
|
this.completedOperations.set(operationId, completedData);
|
||||||
@@ -117,8 +142,9 @@ class AsyncOperationManager {
|
|||||||
// Trim completed operations if exceeding maximum
|
// Trim completed operations if exceeding maximum
|
||||||
if (this.completedOperations.size > this.maxCompletedOperations) {
|
if (this.completedOperations.size > this.maxCompletedOperations) {
|
||||||
// Get the oldest operation (sorted by endTime)
|
// Get the oldest operation (sorted by endTime)
|
||||||
const oldest = [...this.completedOperations.entries()]
|
const oldest = [...this.completedOperations.entries()].sort(
|
||||||
.sort((a, b) => a[1].endTime - b[1].endTime)[0];
|
(a, b) => a[1].endTime - b[1].endTime
|
||||||
|
)[0];
|
||||||
|
|
||||||
if (oldest) {
|
if (oldest) {
|
||||||
this.completedOperations.delete(oldest[0]);
|
this.completedOperations.delete(oldest[0]);
|
||||||
@@ -137,9 +163,17 @@ class AsyncOperationManager {
|
|||||||
try {
|
try {
|
||||||
// Use the reportProgress function captured from the original context
|
// Use the reportProgress function captured from the original context
|
||||||
operation.reportProgress(progress);
|
operation.reportProgress(progress);
|
||||||
this.log(operationId, 'debug', `Reported progress: ${JSON.stringify(progress)}`);
|
this.log(
|
||||||
|
operationId,
|
||||||
|
'debug',
|
||||||
|
`Reported progress: ${JSON.stringify(progress)}`
|
||||||
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.log(operationId, 'warn', `Failed to report progress: ${err.message}`);
|
this.log(
|
||||||
|
operationId,
|
||||||
|
'warn',
|
||||||
|
`Failed to report progress: ${err.message}`
|
||||||
|
);
|
||||||
// Don't stop the operation, just log the reporting failure
|
// Don't stop the operation, just log the reporting failure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,7 +194,7 @@ class AsyncOperationManager {
|
|||||||
startTime: operation.startTime,
|
startTime: operation.startTime,
|
||||||
endTime: operation.endTime,
|
endTime: operation.endTime,
|
||||||
result: operation.result,
|
result: operation.result,
|
||||||
error: operation.error,
|
error: operation.error
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +239,7 @@ class AsyncOperationManager {
|
|||||||
|
|
||||||
emit(eventName, data) {
|
emit(eventName, data) {
|
||||||
if (this.listeners.has(eventName)) {
|
if (this.listeners.has(eventName)) {
|
||||||
this.listeners.get(eventName).forEach(listener => listener(data));
|
this.listeners.get(eventName).forEach((listener) => listener(data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,11 @@
|
|||||||
* @returns {Promise<any>} The result of the actionFn.
|
* @returns {Promise<any>} The result of the actionFn.
|
||||||
*/
|
*/
|
||||||
export async function withSessionEnv(sessionEnv, actionFn) {
|
export async function withSessionEnv(sessionEnv, actionFn) {
|
||||||
if (!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
|
// If no sessionEnv is provided, just run the action directly
|
||||||
return await actionFn();
|
return await actionFn();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,11 @@ import path from 'path';
|
|||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
// Removed lastFoundProjectRoot as it's not suitable for MCP server
|
||||||
|
// Assuming getProjectRootFromSession is available
|
||||||
|
import { getProjectRootFromSession } from '../../tools/utils.js';
|
||||||
|
|
||||||
// Store last found project root to improve performance on subsequent calls (primarily for CLI)
|
// Project marker files that indicate a potential project root (can be kept for potential future use or logging)
|
||||||
export let lastFoundProjectRoot = null;
|
|
||||||
|
|
||||||
// Project marker files that indicate a potential project root
|
|
||||||
export const PROJECT_MARKERS = [
|
export const PROJECT_MARKERS = [
|
||||||
// Task Master specific
|
// Task Master specific
|
||||||
'tasks.json',
|
'tasks.json',
|
||||||
@@ -75,98 +75,142 @@ export function getPackagePath() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the absolute path to the tasks.json file based on project root and arguments.
|
* Finds the absolute path to the tasks.json file and returns the validated project root.
|
||||||
|
* Determines the project root using args and session, validates it, searches for tasks.json.
|
||||||
|
*
|
||||||
* @param {Object} args - Command arguments, potentially including 'projectRoot' and 'file'.
|
* @param {Object} args - Command arguments, potentially including 'projectRoot' and 'file'.
|
||||||
* @param {Object} log - Logger object.
|
* @param {Object} log - Logger object.
|
||||||
* @returns {string} - Absolute path to the tasks.json file.
|
* @param {Object} session - MCP session object.
|
||||||
* @throws {Error} - If tasks.json cannot be found.
|
* @returns {Promise<{tasksPath: string, validatedProjectRoot: string}>} - Object containing absolute path to tasks.json and the validated root.
|
||||||
|
* @throws {Error} - If a valid project root cannot be determined or tasks.json cannot be found.
|
||||||
*/
|
*/
|
||||||
export function findTasksJsonPath(args, log) {
|
export function findTasksJsonPath(args, log, session) {
|
||||||
// PRECEDENCE ORDER for finding tasks.json:
|
const homeDir = os.homedir();
|
||||||
// 1. Explicitly provided `projectRoot` in args (Highest priority, expected in MCP context)
|
let targetDirectory = null;
|
||||||
// 2. Previously found/cached `lastFoundProjectRoot` (primarily for CLI performance)
|
let rootSource = 'unknown';
|
||||||
// 3. Search upwards from current working directory (`process.cwd()`) - CLI usage
|
|
||||||
|
|
||||||
// 1. If project root is explicitly provided (e.g., from MCP session), use it directly
|
log.info(
|
||||||
if (args.projectRoot) {
|
`Finding tasks.json path. Args: ${JSON.stringify(args)}, Session available: ${!!session}`
|
||||||
const projectRoot = args.projectRoot;
|
);
|
||||||
log.info(`Using explicitly provided project root: ${projectRoot}`);
|
|
||||||
try {
|
// --- Determine Target Directory ---
|
||||||
// This will throw if tasks.json isn't found within this root
|
if (
|
||||||
return findTasksJsonInDirectory(projectRoot, args.file, log);
|
args.projectRoot &&
|
||||||
} catch (error) {
|
args.projectRoot !== '/' &&
|
||||||
// Include debug info in error
|
args.projectRoot !== homeDir
|
||||||
const debugInfo = {
|
) {
|
||||||
projectRoot,
|
log.info(`Using projectRoot directly from args: ${args.projectRoot}`);
|
||||||
currentDir: process.cwd(),
|
targetDirectory = args.projectRoot;
|
||||||
serverDir: path.dirname(process.argv[1]),
|
rootSource = 'args.projectRoot';
|
||||||
possibleProjectRoot: path.resolve(path.dirname(process.argv[1]), '../..'),
|
} else {
|
||||||
lastFoundProjectRoot,
|
log.warn(
|
||||||
searchedPaths: error.message
|
`args.projectRoot ('${args.projectRoot}') is missing or invalid. Attempting to derive from session.`
|
||||||
|
);
|
||||||
|
const sessionDerivedPath = getProjectRootFromSession(session, log);
|
||||||
|
if (
|
||||||
|
sessionDerivedPath &&
|
||||||
|
sessionDerivedPath !== '/' &&
|
||||||
|
sessionDerivedPath !== homeDir
|
||||||
|
) {
|
||||||
|
log.info(
|
||||||
|
`Using project root derived from session: ${sessionDerivedPath}`
|
||||||
|
);
|
||||||
|
targetDirectory = sessionDerivedPath;
|
||||||
|
rootSource = 'session';
|
||||||
|
} else {
|
||||||
|
log.error(
|
||||||
|
`Could not derive a valid project root from session. Session path='${sessionDerivedPath}'`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- Validate the final targetDirectory ---
|
||||||
|
if (!targetDirectory) {
|
||||||
|
const error = new Error(
|
||||||
|
`Cannot find tasks.json: Could not determine a valid project root directory. Please ensure a workspace/folder is open or specify projectRoot.`
|
||||||
|
);
|
||||||
|
error.code = 'INVALID_PROJECT_ROOT';
|
||||||
|
error.details = {
|
||||||
|
attemptedArgsProjectRoot: args.projectRoot,
|
||||||
|
sessionAvailable: !!session,
|
||||||
|
// Add session derived path attempt for better debugging
|
||||||
|
attemptedSessionDerivedPath: getProjectRootFromSession(session, {
|
||||||
|
info: () => {},
|
||||||
|
warn: () => {},
|
||||||
|
error: () => {}
|
||||||
|
}), // Call again silently for details
|
||||||
|
finalDeterminedRoot: targetDirectory // Will be null here
|
||||||
};
|
};
|
||||||
|
log.error(`Validation failed: ${error.message}`, error.details);
|
||||||
error.message = `Tasks file not found in any of the expected locations relative to project root "${projectRoot}" (from session).\nDebug Info: ${JSON.stringify(debugInfo, null, 2)}`;
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Verify targetDirectory exists ---
|
||||||
|
if (!fs.existsSync(targetDirectory)) {
|
||||||
|
const error = new Error(
|
||||||
|
`Determined project root directory does not exist: ${targetDirectory}`
|
||||||
|
);
|
||||||
|
error.code = 'PROJECT_ROOT_NOT_FOUND';
|
||||||
|
error.details = {
|
||||||
|
/* ... add details ... */
|
||||||
|
};
|
||||||
|
log.error(error.message, error.details);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
if (!fs.statSync(targetDirectory).isDirectory()) {
|
||||||
|
const error = new Error(
|
||||||
|
`Determined project root path is not a directory: ${targetDirectory}`
|
||||||
|
);
|
||||||
|
error.code = 'PROJECT_ROOT_NOT_A_DIRECTORY';
|
||||||
|
error.details = {
|
||||||
|
/* ... add details ... */
|
||||||
|
};
|
||||||
|
log.error(error.message, error.details);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Fallback logic primarily for CLI or when projectRoot isn't passed ---
|
// --- Search within the validated targetDirectory ---
|
||||||
|
log.info(
|
||||||
// 2. If we have a last known project root that worked, try it first
|
`Validated project root (${rootSource}): ${targetDirectory}. Searching for tasks file.`
|
||||||
if (lastFoundProjectRoot) {
|
);
|
||||||
log.info(`Trying last known project root: ${lastFoundProjectRoot}`);
|
|
||||||
try {
|
try {
|
||||||
// Use the cached root
|
const tasksPath = findTasksJsonInDirectory(targetDirectory, args.file, log);
|
||||||
const tasksPath = findTasksJsonInDirectory(lastFoundProjectRoot, args.file, log);
|
// Return both the tasks path and the validated root
|
||||||
return tasksPath; // Return if found in cached root
|
return { tasksPath: tasksPath, validatedProjectRoot: targetDirectory };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.info(`Task file not found in last known project root, continuing search.`);
|
// Augment the error
|
||||||
// Continue with search if not found in cache
|
error.message = `Tasks file not found within validated project root "${targetDirectory}" (source: ${rootSource}). Ensure 'tasks.json' exists at the root or in a 'tasks/' subdirectory.\nOriginal Error: ${error.message}`;
|
||||||
}
|
error.details = {
|
||||||
}
|
...(error.details || {}), // Keep original details if any
|
||||||
|
validatedProjectRoot: targetDirectory,
|
||||||
// 3. Start search from current directory (most common CLI scenario)
|
rootSource: rootSource,
|
||||||
const startDir = process.cwd();
|
attemptedArgsProjectRoot: args.projectRoot,
|
||||||
log.info(`Searching for tasks.json starting from current directory: ${startDir}`);
|
sessionAvailable: !!session
|
||||||
|
};
|
||||||
// Try to find tasks.json by walking up the directory tree from cwd
|
log.error(`Search failed: ${error.message}`, error.details);
|
||||||
try {
|
|
||||||
// This will throw if not found in the CWD tree
|
|
||||||
return findTasksJsonWithParentSearch(startDir, args.file, log);
|
|
||||||
} catch (error) {
|
|
||||||
// If all attempts fail, augment and throw the original error from CWD search
|
|
||||||
error.message = `${error.message}\n\nPossible solutions:\n1. Run the command from your project directory containing tasks.json\n2. Use --project-root=/path/to/project to specify the project location (if using CLI)\n3. Ensure the project root is correctly passed from the client (if using MCP)\n\nCurrent working directory: ${startDir}\nLast known project root: ${lastFoundProjectRoot}\nProject root from args: ${args.projectRoot}`;
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a directory contains any project marker files or directories
|
* Search for tasks.json in a specific directory (now assumes dirPath is a validated project root)
|
||||||
* @param {string} dirPath - Directory to check
|
* @param {string} dirPath - The validated project root directory to search in.
|
||||||
* @returns {boolean} - True if the directory contains any project markers
|
* @param {string} explicitFilePath - Optional explicit file path relative to dirPath (e.g., args.file)
|
||||||
*/
|
|
||||||
function hasProjectMarkers(dirPath) {
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Search for tasks.json in a specific directory
|
|
||||||
* @param {string} dirPath - Directory to search in
|
|
||||||
* @param {string} explicitFilePath - Optional explicit file path relative to dirPath
|
|
||||||
* @param {Object} log - Logger object
|
* @param {Object} log - Logger object
|
||||||
* @returns {string} - Absolute path to tasks.json
|
* @returns {string} - Absolute path to tasks.json
|
||||||
* @throws {Error} - If tasks.json cannot be found
|
* @throws {Error} - If tasks.json cannot be found in the standard locations within dirPath.
|
||||||
*/
|
*/
|
||||||
function findTasksJsonInDirectory(dirPath, explicitFilePath, log) {
|
function findTasksJsonInDirectory(dirPath, explicitFilePath, log) {
|
||||||
const possiblePaths = [];
|
const possiblePaths = [];
|
||||||
|
|
||||||
// 1. If a file is explicitly provided relative to dirPath
|
// 1. If an explicit file path is provided (relative to dirPath)
|
||||||
if (explicitFilePath) {
|
if (explicitFilePath) {
|
||||||
possiblePaths.push(path.resolve(dirPath, explicitFilePath));
|
// Ensure it's treated as relative to the project root if not absolute
|
||||||
|
const resolvedExplicitPath = path.isAbsolute(explicitFilePath)
|
||||||
|
? explicitFilePath
|
||||||
|
: path.resolve(dirPath, explicitFilePath);
|
||||||
|
possiblePaths.push(resolvedExplicitPath);
|
||||||
|
log.info(`Explicit file path provided, checking: ${resolvedExplicitPath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Check the standard locations relative to dirPath
|
// 2. Check the standard locations relative to dirPath
|
||||||
@@ -175,98 +219,152 @@ function findTasksJsonInDirectory(dirPath, explicitFilePath, log) {
|
|||||||
path.join(dirPath, 'tasks', 'tasks.json')
|
path.join(dirPath, 'tasks', 'tasks.json')
|
||||||
);
|
);
|
||||||
|
|
||||||
log.info(`Checking potential task file paths: ${possiblePaths.join(', ')}`);
|
// Deduplicate paths in case explicitFilePath matches a standard location
|
||||||
|
const uniquePaths = [...new Set(possiblePaths)];
|
||||||
|
|
||||||
|
log.info(
|
||||||
|
`Checking for tasks file in validated root ${dirPath}. Potential paths: ${uniquePaths.join(', ')}`
|
||||||
|
);
|
||||||
|
|
||||||
// Find the first existing path
|
// Find the first existing path
|
||||||
for (const p of possiblePaths) {
|
for (const p of uniquePaths) {
|
||||||
log.info(`Checking if exists: ${p}`);
|
// log.info(`Checking if exists: ${p}`); // Can reduce verbosity
|
||||||
const exists = fs.existsSync(p);
|
const exists = fs.existsSync(p);
|
||||||
log.info(`Path ${p} exists: ${exists}`);
|
// log.info(`Path ${p} exists: ${exists}`); // Can reduce verbosity
|
||||||
|
|
||||||
if (exists) {
|
if (exists) {
|
||||||
log.info(`Found tasks file at: ${p}`);
|
log.info(`Found tasks file at: ${p}`);
|
||||||
// Store the project root for future use
|
// No need to set lastFoundProjectRoot anymore
|
||||||
lastFoundProjectRoot = dirPath;
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no file was found, throw an error
|
// 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(
|
||||||
error.code = 'TASKS_FILE_NOT_FOUND';
|
`Tasks file not found in any of the expected locations within directory ${dirPath}: ${uniquePaths.join(', ')}`
|
||||||
|
);
|
||||||
|
error.code = 'TASKS_FILE_NOT_FOUND_IN_ROOT';
|
||||||
|
error.details = { searchedDirectory: dirPath, checkedPaths: uniquePaths };
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Removed findTasksJsonWithParentSearch, hasProjectMarkers, and findTasksWithNpmConsideration
|
||||||
|
// as the project root is now determined upfront and validated.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolves a relative path against the project root, ensuring it's within the project.
|
||||||
|
* @param {string} relativePath - The relative path (e.g., 'scripts/report.json').
|
||||||
|
* @param {string} projectRoot - The validated absolute path to the project root.
|
||||||
|
* @param {Object} log - Logger object.
|
||||||
|
* @returns {string} - The absolute path.
|
||||||
|
* @throws {Error} - If the resolved path is outside the project root or resolution fails.
|
||||||
|
*/
|
||||||
|
export function resolveProjectPath(relativePath, projectRoot, log) {
|
||||||
|
if (!projectRoot || !path.isAbsolute(projectRoot)) {
|
||||||
|
log.error(
|
||||||
|
`Cannot resolve project path: Invalid projectRoot provided: ${projectRoot}`
|
||||||
|
);
|
||||||
|
throw new Error(
|
||||||
|
`Internal Error: Cannot resolve project path due to invalid projectRoot: ${projectRoot}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!relativePath || typeof relativePath !== 'string') {
|
||||||
|
log.error(
|
||||||
|
`Cannot resolve project path: Invalid relativePath provided: ${relativePath}`
|
||||||
|
);
|
||||||
|
throw new Error(
|
||||||
|
`Internal Error: Cannot resolve project path due to invalid relativePath: ${relativePath}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If relativePath is already absolute, check if it's within the project root
|
||||||
|
if (path.isAbsolute(relativePath)) {
|
||||||
|
if (!relativePath.startsWith(projectRoot)) {
|
||||||
|
log.error(
|
||||||
|
`Path Security Violation: Absolute path \"${relativePath}\" provided is outside the project root \"${projectRoot}\"`
|
||||||
|
);
|
||||||
|
throw new Error(
|
||||||
|
`Provided absolute path is outside the project directory: ${relativePath}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
log.info(
|
||||||
|
`Provided path is already absolute and within project root: ${relativePath}`
|
||||||
|
);
|
||||||
|
return relativePath; // Return as is if valid absolute path within project
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve relative path against project root
|
||||||
|
const absolutePath = path.resolve(projectRoot, relativePath);
|
||||||
|
|
||||||
|
// Security check: Ensure the resolved path is still within the project root boundary
|
||||||
|
// Normalize paths to handle potential .. usages properly before comparison
|
||||||
|
const normalizedAbsolutePath = path.normalize(absolutePath);
|
||||||
|
const normalizedProjectRoot = path.normalize(projectRoot + path.sep); // Ensure trailing separator for accurate startsWith check
|
||||||
|
|
||||||
|
if (
|
||||||
|
!normalizedAbsolutePath.startsWith(normalizedProjectRoot) &&
|
||||||
|
normalizedAbsolutePath !== path.normalize(projectRoot)
|
||||||
|
) {
|
||||||
|
log.error(
|
||||||
|
`Path Security Violation: Resolved path \"${normalizedAbsolutePath}\" is outside project root \"${normalizedProjectRoot}\"`
|
||||||
|
);
|
||||||
|
throw new Error(
|
||||||
|
`Resolved path is outside the project directory: ${relativePath}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info(`Resolved project path: \"${relativePath}\" -> \"${absolutePath}\"`);
|
||||||
|
return absolutePath;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively search for tasks.json in the given directory and parent directories
|
* Ensures a directory exists, creating it if necessary.
|
||||||
* Also looks for project markers to identify potential project roots
|
* Also verifies that if the path already exists, it is indeed a directory.
|
||||||
* @param {string} startDir - Directory to start searching from
|
* @param {string} dirPath - The absolute path to the directory.
|
||||||
* @param {string} explicitFilePath - Optional explicit file path
|
* @param {Object} log - Logger object.
|
||||||
* @param {Object} log - Logger object
|
|
||||||
* @returns {string} - Absolute path to tasks.json
|
|
||||||
* @throws {Error} - If tasks.json cannot be found in any parent directory
|
|
||||||
*/
|
*/
|
||||||
function findTasksJsonWithParentSearch(startDir, explicitFilePath, log) {
|
export function ensureDirectoryExists(dirPath, log) {
|
||||||
let currentDir = startDir;
|
// Validate dirPath is an absolute path before proceeding
|
||||||
const rootDir = path.parse(currentDir).root;
|
if (!path.isAbsolute(dirPath)) {
|
||||||
|
log.error(
|
||||||
|
`Cannot ensure directory: Path provided is not absolute: ${dirPath}`
|
||||||
|
);
|
||||||
|
throw new Error(
|
||||||
|
`Internal Error: ensureDirectoryExists requires an absolute path.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Keep traversing up until we hit the root directory
|
if (!fs.existsSync(dirPath)) {
|
||||||
while (currentDir !== rootDir) {
|
log.info(`Directory does not exist, creating recursively: ${dirPath}`);
|
||||||
// First check for tasks.json directly
|
|
||||||
try {
|
try {
|
||||||
return findTasksJsonInDirectory(currentDir, explicitFilePath, log);
|
fs.mkdirSync(dirPath, { recursive: true });
|
||||||
|
log.info(`Successfully created directory: ${dirPath}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// If tasks.json not found but the directory has project markers,
|
log.error(`Failed to create directory ${dirPath}: ${error.message}`);
|
||||||
// log it as a potential project root (helpful for debugging)
|
// Re-throw the error after logging
|
||||||
if (hasProjectMarkers(currentDir)) {
|
throw new Error(
|
||||||
log.info(`Found project markers in ${currentDir}, but no tasks.json`);
|
`Could not create directory: ${dirPath}. Reason: ${error.message}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// Move up to parent directory
|
// Path exists, verify it's a directory
|
||||||
const parentDir = path.dirname(currentDir);
|
|
||||||
|
|
||||||
// Check if we've reached the root
|
|
||||||
if (parentDir === currentDir) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
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.`);
|
|
||||||
error.code = 'TASKS_FILE_NOT_FOUND';
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: findTasksWithNpmConsideration is not used by findTasksJsonPath and might be legacy or used elsewhere.
|
|
||||||
// If confirmed unused, it could potentially be removed in a separate cleanup.
|
|
||||||
function findTasksWithNpmConsideration(startDir, log) {
|
|
||||||
// First try our recursive parent search from cwd
|
|
||||||
try {
|
try {
|
||||||
return findTasksJsonWithParentSearch(startDir, null, log);
|
const stats = fs.statSync(dirPath);
|
||||||
|
if (!stats.isDirectory()) {
|
||||||
|
log.error(`Path exists but is not a directory: ${dirPath}`);
|
||||||
|
throw new Error(
|
||||||
|
`Expected directory but found file at path: ${dirPath}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
log.info(`Directory already exists and is valid: ${dirPath}`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// If that fails, try looking relative to the executable location
|
// Handle potential errors from statSync (e.g., permissions) or the explicit throw above
|
||||||
const execPath = process.argv[1];
|
log.error(
|
||||||
const execDir = path.dirname(execPath);
|
`Error checking existing directory ${dirPath}: ${error.message}`
|
||||||
log.info(`Looking for tasks file relative to executable at: ${execDir}`);
|
);
|
||||||
|
throw new Error(
|
||||||
try {
|
`Error verifying existing directory: ${dirPath}. Reason: ${error.message}`
|
||||||
return findTasksJsonWithParentSearch(execDir, null, log);
|
);
|
||||||
} catch (secondError) {
|
|
||||||
// If that also fails, check standard locations in user's home directory
|
|
||||||
const homeDir = os.homedir();
|
|
||||||
log.info(`Looking for tasks file in home directory: ${homeDir}`);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Check standard locations in home dir
|
|
||||||
return findTasksJsonInDirectory(path.join(homeDir, '.task-master'), null, log);
|
|
||||||
} catch (thirdError) {
|
|
||||||
// If all approaches fail, throw the original error
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { FastMCP } from "fastmcp";
|
import { FastMCP } from 'fastmcp';
|
||||||
import path from "path";
|
import path from 'path';
|
||||||
import dotenv from "dotenv";
|
import dotenv from 'dotenv';
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from 'url';
|
||||||
import fs from "fs";
|
import fs from 'fs';
|
||||||
import logger from "./logger.js";
|
import logger from './logger.js';
|
||||||
import { registerTaskMasterTools } from "./tools/index.js";
|
import { registerTaskMasterTools } from './tools/index.js';
|
||||||
import { asyncOperationManager } from './core/utils/async-manager.js';
|
import { asyncOperationManager } from './core/utils/async-manager.js';
|
||||||
|
|
||||||
// Load environment variables
|
// Load environment variables
|
||||||
@@ -20,12 +20,12 @@ const __dirname = path.dirname(__filename);
|
|||||||
class TaskMasterMCPServer {
|
class TaskMasterMCPServer {
|
||||||
constructor() {
|
constructor() {
|
||||||
// Get version from package.json using synchronous fs
|
// Get version from package.json using synchronous fs
|
||||||
const packagePath = path.join(__dirname, "../../package.json");
|
const packagePath = path.join(__dirname, '../../package.json');
|
||||||
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8"));
|
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
||||||
|
|
||||||
this.options = {
|
this.options = {
|
||||||
name: "Task Master MCP Server",
|
name: 'Task Master MCP Server',
|
||||||
version: packageJson.version,
|
version: packageJson.version
|
||||||
};
|
};
|
||||||
|
|
||||||
this.server = new FastMCP(this.options);
|
this.server = new FastMCP(this.options);
|
||||||
@@ -71,7 +71,7 @@ class TaskMasterMCPServer {
|
|||||||
|
|
||||||
// Start the FastMCP server with increased timeout
|
// Start the FastMCP server with increased timeout
|
||||||
await this.server.start({
|
await this.server.start({
|
||||||
transportType: "stdio",
|
transportType: 'stdio',
|
||||||
timeout: 120000 // 2 minutes timeout (in milliseconds)
|
timeout: 120000 // 2 minutes timeout (in milliseconds)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import chalk from "chalk";
|
import chalk from 'chalk';
|
||||||
import { isSilentMode } from "../../scripts/modules/utils.js";
|
import { isSilentMode } from '../../scripts/modules/utils.js';
|
||||||
|
|
||||||
// Define log levels
|
// Define log levels
|
||||||
const LOG_LEVELS = {
|
const LOG_LEVELS = {
|
||||||
@@ -7,12 +7,12 @@ const LOG_LEVELS = {
|
|||||||
info: 1,
|
info: 1,
|
||||||
warn: 2,
|
warn: 2,
|
||||||
error: 3,
|
error: 3,
|
||||||
success: 4,
|
success: 4
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get log level from environment or default to info
|
// Get log level from environment or default to info
|
||||||
const LOG_LEVEL = process.env.LOG_LEVEL
|
const LOG_LEVEL = process.env.LOG_LEVEL
|
||||||
? LOG_LEVELS[process.env.LOG_LEVEL.toLowerCase()] ?? LOG_LEVELS.info
|
? (LOG_LEVELS[process.env.LOG_LEVEL.toLowerCase()] ?? LOG_LEVELS.info)
|
||||||
: LOG_LEVELS.info;
|
: LOG_LEVELS.info;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,40 +28,50 @@ function log(level, ...args) {
|
|||||||
|
|
||||||
// Use text prefixes instead of emojis
|
// Use text prefixes instead of emojis
|
||||||
const prefixes = {
|
const prefixes = {
|
||||||
debug: chalk.gray("[DEBUG]"),
|
debug: chalk.gray('[DEBUG]'),
|
||||||
info: chalk.blue("[INFO]"),
|
info: chalk.blue('[INFO]'),
|
||||||
warn: chalk.yellow("[WARN]"),
|
warn: chalk.yellow('[WARN]'),
|
||||||
error: chalk.red("[ERROR]"),
|
error: chalk.red('[ERROR]'),
|
||||||
success: chalk.green("[SUCCESS]"),
|
success: chalk.green('[SUCCESS]')
|
||||||
};
|
};
|
||||||
|
|
||||||
if (LOG_LEVELS[level] !== undefined && LOG_LEVELS[level] >= LOG_LEVEL) {
|
if (LOG_LEVELS[level] !== undefined && LOG_LEVELS[level] >= LOG_LEVEL) {
|
||||||
const prefix = prefixes[level] || "";
|
const prefix = prefixes[level] || '';
|
||||||
let coloredArgs = args;
|
let coloredArgs = args;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case "error":
|
case 'error':
|
||||||
coloredArgs = args.map(arg => typeof arg === 'string' ? chalk.red(arg) : arg);
|
coloredArgs = args.map((arg) =>
|
||||||
|
typeof arg === 'string' ? chalk.red(arg) : arg
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "warn":
|
case 'warn':
|
||||||
coloredArgs = args.map(arg => typeof arg === 'string' ? chalk.yellow(arg) : arg);
|
coloredArgs = args.map((arg) =>
|
||||||
|
typeof arg === 'string' ? chalk.yellow(arg) : arg
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "success":
|
case 'success':
|
||||||
coloredArgs = args.map(arg => typeof arg === 'string' ? chalk.green(arg) : arg);
|
coloredArgs = args.map((arg) =>
|
||||||
|
typeof arg === 'string' ? chalk.green(arg) : arg
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "info":
|
case 'info':
|
||||||
coloredArgs = args.map(arg => typeof arg === 'string' ? chalk.blue(arg) : arg);
|
coloredArgs = args.map((arg) =>
|
||||||
|
typeof arg === 'string' ? chalk.blue(arg) : arg
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case "debug":
|
case 'debug':
|
||||||
coloredArgs = args.map(arg => typeof arg === 'string' ? chalk.gray(arg) : arg);
|
coloredArgs = args.map((arg) =>
|
||||||
|
typeof arg === 'string' ? chalk.gray(arg) : arg
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
// default: use original args (no color)
|
// default: use original args (no color)
|
||||||
}
|
}
|
||||||
} catch (colorError) {
|
} catch (colorError) {
|
||||||
// Fallback if chalk fails on an argument
|
// Fallback if chalk fails on an argument
|
||||||
// Use console.error here for internal logger errors, separate from normal logging
|
// 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;
|
coloredArgs = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,15 +88,18 @@ function log(level, ...args) {
|
|||||||
* @returns {Object} Logger object with info, error, debug, warn, and success methods
|
* @returns {Object} Logger object with info, error, debug, warn, and success methods
|
||||||
*/
|
*/
|
||||||
export function createLogger() {
|
export function createLogger() {
|
||||||
const createLogMethod = (level) => (...args) => log(level, ...args);
|
const createLogMethod =
|
||||||
|
(level) =>
|
||||||
|
(...args) =>
|
||||||
|
log(level, ...args);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
debug: createLogMethod("debug"),
|
debug: createLogMethod('debug'),
|
||||||
info: createLogMethod("info"),
|
info: createLogMethod('info'),
|
||||||
warn: createLogMethod("warn"),
|
warn: createLogMethod('warn'),
|
||||||
error: createLogMethod("error"),
|
error: createLogMethod('error'),
|
||||||
success: createLogMethod("success"),
|
success: createLogMethod('success'),
|
||||||
log: log, // Also expose the raw log function
|
log: log // Also expose the raw log function
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool for adding a dependency to a task
|
* Tool for adding a dependency to a task
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { addDependencyDirect } from "../core/task-master-core.js";
|
import { addDependencyDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the addDependency tool with the MCP server
|
* Register the addDependency tool with the MCP server
|
||||||
@@ -17,17 +17,31 @@ import { addDependencyDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerAddDependencyTool(server) {
|
export function registerAddDependencyTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "add_dependency",
|
name: 'add_dependency',
|
||||||
description: "Add a dependency relationship between two tasks",
|
description: 'Add a dependency relationship between two tasks',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
id: z.string().describe("ID of task that will depend on another task"),
|
id: z.string().describe('ID of task that will depend on another task'),
|
||||||
dependsOn: z.string().describe("ID of task that will become a dependency"),
|
dependsOn: z
|
||||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
.string()
|
||||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
.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()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
'Root directory of the project (default: current working directory)'
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session, reportProgress }) => {
|
execute: async (args, { log, session, reportProgress }) => {
|
||||||
try {
|
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 });
|
reportProgress({ progress: 0 });
|
||||||
|
|
||||||
// Get project root using the utility function
|
// Get project root using the utility function
|
||||||
@@ -40,10 +54,14 @@ export function registerAddDependencyTool(server) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call the direct function with the resolved rootFolder
|
// Call the direct function with the resolved rootFolder
|
||||||
const result = await addDependencyDirect({
|
const result = await addDependencyDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log, { reportProgress, mcpLog: log, session});
|
},
|
||||||
|
log,
|
||||||
|
{ reportProgress, mcpLog: log, session }
|
||||||
|
);
|
||||||
|
|
||||||
reportProgress({ progress: 100 });
|
reportProgress({ progress: 100 });
|
||||||
|
|
||||||
@@ -60,6 +78,6 @@ export function registerAddDependencyTool(server) {
|
|||||||
log.error(`Error in addDependency tool: ${error.message}`);
|
log.error(`Error in addDependency tool: ${error.message}`);
|
||||||
return createErrorResponse(error.message);
|
return createErrorResponse(error.message);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool for adding subtasks to existing tasks
|
* Tool for adding subtasks to existing tasks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { addSubtaskDirect } from "../core/task-master-core.js";
|
import { addSubtaskDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the addSubtask tool with the MCP server
|
* Register the addSubtask tool with the MCP server
|
||||||
@@ -17,19 +17,50 @@ import { addSubtaskDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerAddSubtaskTool(server) {
|
export function registerAddSubtaskTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "add_subtask",
|
name: 'add_subtask',
|
||||||
description: "Add a subtask to an existing task",
|
description: 'Add a subtask to an existing task',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
id: z.string().describe("Parent task ID (required)"),
|
id: z.string().describe('Parent task ID (required)'),
|
||||||
taskId: z.string().optional().describe("Existing task ID to convert to subtask"),
|
taskId: z
|
||||||
title: z.string().optional().describe("Title for the new subtask (when creating a new subtask)"),
|
.string()
|
||||||
description: z.string().optional().describe("Description for the new subtask"),
|
.optional()
|
||||||
details: z.string().optional().describe("Implementation details for the new subtask"),
|
.describe('Existing task ID to convert to subtask'),
|
||||||
status: z.string().optional().describe("Status for the new subtask (default: 'pending')"),
|
title: z
|
||||||
dependencies: z.string().optional().describe("Comma-separated list of dependency IDs for the new subtask"),
|
.string()
|
||||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
.optional()
|
||||||
skipGenerate: z.boolean().optional().describe("Skip regenerating task files"),
|
.describe('Title for the new subtask (when creating a new subtask)'),
|
||||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
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()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
'Root directory of the project (default: current working directory)'
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session, reportProgress }) => {
|
execute: async (args, { log, session, reportProgress }) => {
|
||||||
try {
|
try {
|
||||||
@@ -42,10 +73,14 @@ export function registerAddSubtaskTool(server) {
|
|||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await addSubtaskDirect({
|
const result = await addSubtaskDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log, { reportProgress, mcpLog: log, session});
|
},
|
||||||
|
log,
|
||||||
|
{ reportProgress, mcpLog: log, session }
|
||||||
|
);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
log.info(`Subtask added successfully: ${result.data.message}`);
|
log.info(`Subtask added successfully: ${result.data.message}`);
|
||||||
@@ -58,6 +93,6 @@ export function registerAddSubtaskTool(server) {
|
|||||||
log.error(`Error in addSubtask tool: ${error.message}`);
|
log.error(`Error in addSubtask tool: ${error.message}`);
|
||||||
return createErrorResponse(error.message);
|
return createErrorResponse(error.message);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,15 +3,15 @@
|
|||||||
* Tool to add a new task using AI
|
* Tool to add a new task using AI
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
createContentResponse,
|
createContentResponse,
|
||||||
getProjectRootFromSession,
|
getProjectRootFromSession,
|
||||||
executeTaskMasterCommand,
|
executeTaskMasterCommand,
|
||||||
handleApiResult
|
handleApiResult
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { addTaskDirect } from "../core/task-master-core.js";
|
import { addTaskDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the addTask tool with the MCP server
|
* Register the addTask tool with the MCP server
|
||||||
@@ -19,15 +19,53 @@ import { addTaskDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerAddTaskTool(server) {
|
export function registerAddTaskTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "add_task",
|
name: 'add_task',
|
||||||
description: "Add a new task using AI",
|
description: 'Add a new task using AI',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
prompt: z.string().describe("Description of the task to add"),
|
prompt: z
|
||||||
dependencies: z.string().optional().describe("Comma-separated list of task IDs this task depends on"),
|
.string()
|
||||||
priority: z.string().optional().describe("Task priority (high, medium, low)"),
|
.optional()
|
||||||
file: z.string().optional().describe("Path to the tasks file"),
|
.describe(
|
||||||
projectRoot: z.string().optional().describe("Root directory of the project"),
|
'Description of the task to add (required if not using manual fields)'
|
||||||
research: z.boolean().optional().describe("Whether to use research capabilities for task creation")
|
),
|
||||||
|
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()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
'Root directory of the project (default: current working directory)'
|
||||||
|
),
|
||||||
|
research: z
|
||||||
|
.boolean()
|
||||||
|
.optional()
|
||||||
|
.describe('Whether to use research capabilities for task creation')
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, reportProgress, session }) => {
|
execute: async (args, { log, reportProgress, session }) => {
|
||||||
try {
|
try {
|
||||||
@@ -42,10 +80,14 @@ export function registerAddTaskTool(server) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call the direct function
|
// Call the direct function
|
||||||
const result = await addTaskDirect({
|
const result = await addTaskDirect(
|
||||||
|
{
|
||||||
...args,
|
...args,
|
||||||
projectRoot: rootFolder
|
projectRoot: rootFolder
|
||||||
}, log, { reportProgress, session });
|
},
|
||||||
|
log,
|
||||||
|
{ reportProgress, session }
|
||||||
|
);
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
return handleApiResult(result, log);
|
return handleApiResult(result, log);
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool for analyzing task complexity and generating recommendations
|
* Tool for analyzing task complexity and generating recommendations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse
|
||||||
getProjectRootFromSession
|
// getProjectRootFromSession // No longer needed here
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { analyzeTaskComplexityDirect } from "../core/task-master-core.js";
|
import { analyzeTaskComplexityDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the analyze tool with the MCP server
|
* Register the analyze tool with the MCP server
|
||||||
@@ -17,44 +17,65 @@ import { analyzeTaskComplexityDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerAnalyzeTool(server) {
|
export function registerAnalyzeTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "analyze_project_complexity",
|
name: 'analyze_project_complexity',
|
||||||
description: "Analyze task complexity and generate expansion recommendations",
|
description:
|
||||||
|
'Analyze task complexity and generate expansion recommendations. Requires the project root path.',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
output: z.string().optional().describe("Output file path for the report (default: scripts/task-complexity-report.json)"),
|
projectRoot: z
|
||||||
model: z.string().optional().describe("LLM model to use for analysis (defaults to configured model)"),
|
.string()
|
||||||
threshold: z.union([z.number(), z.string()]).optional().describe("Minimum complexity score to recommend expansion (1-10) (default: 5)"),
|
.describe(
|
||||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
'Required. Absolute path to the root directory of the project being analyzed.'
|
||||||
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)")
|
output: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
'Output file path for the report, relative to projectRoot (default: scripts/task-complexity-report.json)'
|
||||||
|
),
|
||||||
|
threshold: z.coerce
|
||||||
|
.number()
|
||||||
|
.min(1)
|
||||||
|
.max(10)
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
'Minimum complexity score to recommend expansion (1-10) (default: 5). If the complexity score is below this threshold, the tool will not recommend adding subtasks.'
|
||||||
|
),
|
||||||
|
research: z
|
||||||
|
.boolean()
|
||||||
|
.optional()
|
||||||
|
.describe('Use Perplexity AI for research-backed complexity analysis')
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session }) => {
|
execute: async (args, { log, session }) => {
|
||||||
try {
|
try {
|
||||||
log.info(`Analyzing task complexity with args: ${JSON.stringify(args)}`);
|
log.info(
|
||||||
|
`Analyzing task complexity with required projectRoot: ${args.projectRoot}, other args: ${JSON.stringify(args)}`
|
||||||
|
);
|
||||||
|
|
||||||
let rootFolder = getProjectRootFromSession(session, log);
|
const result = await analyzeTaskComplexityDirect(args, log, {
|
||||||
|
session
|
||||||
|
});
|
||||||
|
|
||||||
if (!rootFolder && args.projectRoot) {
|
if (result.success && result.data) {
|
||||||
rootFolder = args.projectRoot;
|
|
||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const result = await analyzeTaskComplexityDirect({
|
|
||||||
projectRoot: rootFolder,
|
|
||||||
...args
|
|
||||||
}, log, { session });
|
|
||||||
|
|
||||||
if (result.success) {
|
|
||||||
log.info(`Task complexity analysis complete: ${result.data.message}`);
|
log.info(`Task complexity analysis complete: ${result.data.message}`);
|
||||||
log.info(`Report summary: ${JSON.stringify(result.data.reportSummary)}`);
|
log.info(
|
||||||
} else {
|
`Report summary: ${JSON.stringify(result.data.reportSummary)}`
|
||||||
log.error(`Failed to analyze task complexity: ${result.error.message}`);
|
);
|
||||||
|
} else if (!result.success && result.error) {
|
||||||
|
log.error(
|
||||||
|
`Failed to analyze task complexity: ${result.error.message} (Code: ${result.error.code})`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return handleApiResult(result, log, 'Error analyzing task complexity');
|
return handleApiResult(result, log, 'Error analyzing task complexity');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Error in analyze tool: ${error.message}`);
|
log.error(
|
||||||
return createErrorResponse(error.message);
|
`Unexpected error in analyze tool execute method: ${error.message}`,
|
||||||
|
{ stack: error.stack }
|
||||||
|
);
|
||||||
|
return createErrorResponse(
|
||||||
|
`Unexpected error in analyze tool: ${error.message}`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool for clearing subtasks from parent tasks
|
* Tool for clearing subtasks from parent tasks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { clearSubtasksDirect } from "../core/task-master-core.js";
|
import { clearSubtasksDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the clearSubtasks tool with the MCP server
|
* Register the clearSubtasks tool with the MCP server
|
||||||
@@ -17,16 +17,31 @@ import { clearSubtasksDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerClearSubtasksTool(server) {
|
export function registerClearSubtasksTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "clear_subtasks",
|
name: 'clear_subtasks',
|
||||||
description: "Clear subtasks from specified tasks",
|
description: 'Clear subtasks from specified tasks',
|
||||||
parameters: z.object({
|
parameters: z
|
||||||
id: z.string().optional().describe("Task IDs (comma-separated) to clear subtasks from"),
|
.object({
|
||||||
all: z.boolean().optional().describe("Clear subtasks from all tasks"),
|
id: z
|
||||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
.string()
|
||||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
.optional()
|
||||||
}).refine(data => data.id || data.all, {
|
.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()
|
||||||
|
.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",
|
message: "Either 'id' or 'all' parameter must be provided",
|
||||||
path: ["id", "all"]
|
path: ['id', 'all']
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session, reportProgress }) => {
|
execute: async (args, { log, session, reportProgress }) => {
|
||||||
try {
|
try {
|
||||||
@@ -40,10 +55,14 @@ export function registerClearSubtasksTool(server) {
|
|||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await clearSubtasksDirect({
|
const result = await clearSubtasksDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log, { reportProgress, mcpLog: log, session});
|
},
|
||||||
|
log,
|
||||||
|
{ reportProgress, mcpLog: log, session }
|
||||||
|
);
|
||||||
|
|
||||||
reportProgress({ progress: 100 });
|
reportProgress({ progress: 100 });
|
||||||
|
|
||||||
@@ -58,6 +77,6 @@ export function registerClearSubtasksTool(server) {
|
|||||||
log.error(`Error in clearSubtasks tool: ${error.message}`);
|
log.error(`Error in clearSubtasks tool: ${error.message}`);
|
||||||
return createErrorResponse(error.message);
|
return createErrorResponse(error.message);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool for displaying the complexity analysis report
|
* Tool for displaying the complexity analysis report
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { complexityReportDirect } from "../core/task-master-core.js";
|
import { complexityReportDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the complexityReport tool with the MCP server
|
* Register the complexityReport tool with the MCP server
|
||||||
@@ -17,15 +17,27 @@ import { complexityReportDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerComplexityReportTool(server) {
|
export function registerComplexityReportTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "complexity_report",
|
name: 'complexity_report',
|
||||||
description: "Display the complexity analysis report in a readable format",
|
description: 'Display the complexity analysis report in a readable format',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
file: z.string().optional().describe("Path to the report file (default: scripts/task-complexity-report.json)"),
|
file: z
|
||||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
.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, reportProgress }) => {
|
execute: async (args, { log, session, reportProgress }) => {
|
||||||
try {
|
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 });
|
// await reportProgress({ progress: 0 });
|
||||||
|
|
||||||
let rootFolder = getProjectRootFromSession(session, log);
|
let rootFolder = getProjectRootFromSession(session, log);
|
||||||
@@ -35,24 +47,37 @@ export function registerComplexityReportTool(server) {
|
|||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await complexityReportDirect({
|
const result = await complexityReportDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log/*, { reportProgress, mcpLog: log, session}*/);
|
},
|
||||||
|
log /*, { reportProgress, mcpLog: log, session}*/
|
||||||
|
);
|
||||||
|
|
||||||
// await reportProgress({ progress: 100 });
|
// await reportProgress({ progress: 100 });
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
log.info(`Successfully retrieved complexity report${result.fromCache ? ' (from cache)' : ''}`);
|
log.info(
|
||||||
|
`Successfully retrieved complexity report${result.fromCache ? ' (from cache)' : ''}`
|
||||||
|
);
|
||||||
} else {
|
} 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) {
|
} catch (error) {
|
||||||
log.error(`Error in complexity-report tool: ${error.message}`);
|
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,13 +3,13 @@
|
|||||||
* Tool for expanding all pending tasks with subtasks
|
* Tool for expanding all pending tasks with subtasks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { expandAllTasksDirect } from "../core/task-master-core.js";
|
import { expandAllTasksDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the expandAll tool with the MCP server
|
* Register the expandAll tool with the MCP server
|
||||||
@@ -17,15 +17,41 @@ import { expandAllTasksDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerExpandAllTool(server) {
|
export function registerExpandAllTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "expand_all",
|
name: 'expand_all',
|
||||||
description: "Expand all pending tasks into subtasks",
|
description: 'Expand all pending tasks into subtasks',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
num: z.string().optional().describe("Number of subtasks to generate for each task"),
|
num: z
|
||||||
research: z.boolean().optional().describe("Enable Perplexity AI for research-backed subtask generation"),
|
.string()
|
||||||
prompt: z.string().optional().describe("Additional context to guide subtask generation"),
|
.optional()
|
||||||
force: z.boolean().optional().describe("Force regeneration of subtasks for tasks that already have them"),
|
.describe('Number of subtasks to generate for each task'),
|
||||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
research: z
|
||||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
.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()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
'Root directory of the project (default: current working directory)'
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session }) => {
|
execute: async (args, { log, session }) => {
|
||||||
try {
|
try {
|
||||||
@@ -38,15 +64,21 @@ export function registerExpandAllTool(server) {
|
|||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await expandAllTasksDirect({
|
const result = await expandAllTasksDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log, { session });
|
},
|
||||||
|
log,
|
||||||
|
{ session }
|
||||||
|
);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
log.info(`Successfully expanded all tasks: ${result.data.message}`);
|
log.info(`Successfully expanded all tasks: ${result.data.message}`);
|
||||||
} else {
|
} 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');
|
return handleApiResult(result, log, 'Error expanding all tasks');
|
||||||
@@ -54,6 +86,6 @@ export function registerExpandAllTool(server) {
|
|||||||
log.error(`Error in expand-all tool: ${error.message}`);
|
log.error(`Error in expand-all tool: ${error.message}`);
|
||||||
return createErrorResponse(error.message);
|
return createErrorResponse(error.message);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,15 +3,15 @@
|
|||||||
* Tool to expand a task into subtasks
|
* Tool to expand a task into subtasks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { expandTaskDirect } from "../core/task-master-core.js";
|
import { expandTaskDirect } from '../core/task-master-core.js';
|
||||||
import fs from "fs";
|
import fs from 'fs';
|
||||||
import path from "path";
|
import path from 'path';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the expand-task tool with the MCP server
|
* Register the expand-task tool with the MCP server
|
||||||
@@ -19,22 +19,31 @@ import path from "path";
|
|||||||
*/
|
*/
|
||||||
export function registerExpandTaskTool(server) {
|
export function registerExpandTaskTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "expand_task",
|
name: 'expand_task',
|
||||||
description: "Expand a task into subtasks for detailed implementation",
|
description: 'Expand a task into subtasks for detailed implementation',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
id: z.string().describe("ID of task to expand"),
|
id: z.string().describe('ID of task to expand'),
|
||||||
num: z.union([z.string(), z.number()]).optional().describe("Number of subtasks to generate"),
|
num: z
|
||||||
research: z.boolean().optional().describe("Use Perplexity AI for research-backed generation"),
|
.union([z.string(), z.number()])
|
||||||
prompt: z.string().optional().describe("Additional context for subtask generation"),
|
.optional()
|
||||||
file: z.string().optional().describe("Path to the tasks file"),
|
.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'),
|
||||||
projectRoot: z
|
projectRoot: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.describe(
|
.describe(
|
||||||
"Root directory of the project (default: current working directory)"
|
'Root directory of the project (default: current working directory)'
|
||||||
),
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, reportProgress, session }) => {
|
execute: async (args, { log, session }) => {
|
||||||
try {
|
try {
|
||||||
log.info(`Starting expand-task with args: ${JSON.stringify(args)}`);
|
log.info(`Starting expand-task with args: ${JSON.stringify(args)}`);
|
||||||
|
|
||||||
@@ -61,10 +70,14 @@ export function registerExpandTaskTool(server) {
|
|||||||
|
|
||||||
// Call direct function with only session in the context, not reportProgress
|
// Call direct function with only session in the context, not reportProgress
|
||||||
// Use the pattern recommended in the MCP guidelines
|
// Use the pattern recommended in the MCP guidelines
|
||||||
const result = await expandTaskDirect({
|
const result = await expandTaskDirect(
|
||||||
|
{
|
||||||
...args,
|
...args,
|
||||||
projectRoot: rootFolder
|
projectRoot: rootFolder
|
||||||
}, log, { session }); // Only pass session, NOT reportProgress
|
},
|
||||||
|
log,
|
||||||
|
{ session }
|
||||||
|
); // Only pass session, NOT reportProgress
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
return handleApiResult(result, log, 'Error expanding task');
|
return handleApiResult(result, log, 'Error expanding task');
|
||||||
@@ -72,6 +85,6 @@ export function registerExpandTaskTool(server) {
|
|||||||
log.error(`Error in expand task tool: ${error.message}`);
|
log.error(`Error in expand task tool: ${error.message}`);
|
||||||
return createErrorResponse(error.message);
|
return createErrorResponse(error.message);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool for automatically fixing invalid task dependencies
|
* Tool for automatically fixing invalid task dependencies
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { fixDependenciesDirect } from "../core/task-master-core.js";
|
import { fixDependenciesDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the fixDependencies tool with the MCP server
|
* Register the fixDependencies tool with the MCP server
|
||||||
@@ -17,11 +17,16 @@ import { fixDependenciesDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerFixDependenciesTool(server) {
|
export function registerFixDependenciesTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "fix_dependencies",
|
name: 'fix_dependencies',
|
||||||
description: "Fix invalid dependencies in tasks automatically",
|
description: 'Fix invalid dependencies in tasks automatically',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
file: z.string().optional().describe("Path to the tasks file"),
|
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
projectRoot: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
'Root directory of the project (default: current working directory)'
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session, reportProgress }) => {
|
execute: async (args, { log, session, reportProgress }) => {
|
||||||
try {
|
try {
|
||||||
@@ -35,10 +40,14 @@ export function registerFixDependenciesTool(server) {
|
|||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await fixDependenciesDirect({
|
const result = await fixDependenciesDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log, { reportProgress, mcpLog: log, session});
|
},
|
||||||
|
log,
|
||||||
|
{ reportProgress, mcpLog: log, session }
|
||||||
|
);
|
||||||
|
|
||||||
await reportProgress({ progress: 100 });
|
await reportProgress({ progress: 100 });
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool to generate individual task files from tasks.json
|
* Tool to generate individual task files from tasks.json
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { generateTaskFilesDirect } from "../core/task-master-core.js";
|
import { generateTaskFilesDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the generate tool with the MCP server
|
* Register the generate tool with the MCP server
|
||||||
@@ -17,17 +17,21 @@ import { generateTaskFilesDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerGenerateTool(server) {
|
export function registerGenerateTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "generate",
|
name: 'generate',
|
||||||
description: "Generates individual task files in tasks/ directory based on tasks.json",
|
description:
|
||||||
|
'Generates individual task files in tasks/ directory based on tasks.json',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
file: z.string().optional().describe("Path to the tasks file"),
|
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||||
output: z.string().optional().describe("Output directory (default: same directory as tasks file)"),
|
output: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.describe('Output directory (default: same directory as tasks file)'),
|
||||||
projectRoot: z
|
projectRoot: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.describe(
|
.describe(
|
||||||
"Root directory of the project (default: current working directory)"
|
'Root directory of the project (default: current working directory)'
|
||||||
),
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session, reportProgress }) => {
|
execute: async (args, { log, session, reportProgress }) => {
|
||||||
try {
|
try {
|
||||||
@@ -41,17 +45,22 @@ export function registerGenerateTool(server) {
|
|||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await generateTaskFilesDirect({
|
const result = await generateTaskFilesDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log/*, { reportProgress, mcpLog: log, session}*/);
|
},
|
||||||
|
log /*, { reportProgress, mcpLog: log, session}*/
|
||||||
|
);
|
||||||
|
|
||||||
// await reportProgress({ progress: 100 });
|
// await reportProgress({ progress: 100 });
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
log.info(`Successfully generated task files: ${result.data.message}`);
|
log.info(`Successfully generated task files: ${result.data.message}`);
|
||||||
} else {
|
} 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');
|
return handleApiResult(result, log, 'Error generating task files');
|
||||||
@@ -59,6 +68,6 @@ export function registerGenerateTool(server) {
|
|||||||
log.error(`Error in generate tool: ${error.message}`);
|
log.error(`Error in generate tool: ${error.message}`);
|
||||||
return createErrorResponse(error.message);
|
return createErrorResponse(error.message);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -10,9 +10,10 @@ import { createErrorResponse, createContentResponse } from './utils.js'; // Assu
|
|||||||
export function registerGetOperationStatusTool(server, asyncManager) {
|
export function registerGetOperationStatusTool(server, asyncManager) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: 'get_operation_status',
|
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({
|
parameters: z.object({
|
||||||
operationId: z.string().describe('The ID of the operation to check.'),
|
operationId: z.string().describe('The ID of the operation to check.')
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log }) => {
|
execute: async (args, { log }) => {
|
||||||
try {
|
try {
|
||||||
@@ -32,11 +33,15 @@ export function registerGetOperationStatusTool(server, asyncManager) {
|
|||||||
|
|
||||||
log.info(`Status for ${operationId}: ${status.status}`);
|
log.info(`Status for ${operationId}: ${status.status}`);
|
||||||
return createContentResponse(status);
|
return createContentResponse(status);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Error in get_operation_status tool: ${error.message}`, { stack: error.stack });
|
log.error(`Error in get_operation_status tool: ${error.message}`, {
|
||||||
return createErrorResponse(`Failed to get operation status: ${error.message}`, 'GET_STATUS_ERROR');
|
stack: error.stack
|
||||||
|
});
|
||||||
|
return createErrorResponse(
|
||||||
|
`Failed to get operation status: ${error.message}`,
|
||||||
|
'GET_STATUS_ERROR'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool to get task details by ID
|
* Tool to get task details by ID
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { showTaskDirect } from "../core/task-master-core.js";
|
import { showTaskDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom processor function that removes allTasks from the response
|
* Custom processor function that removes allTasks from the response
|
||||||
@@ -35,26 +35,30 @@ function processTaskResponse(data) {
|
|||||||
*/
|
*/
|
||||||
export function registerShowTaskTool(server) {
|
export function registerShowTaskTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "get_task",
|
name: 'get_task',
|
||||||
description: "Get detailed information about a specific task",
|
description: 'Get detailed information about a specific task',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
id: z.string().describe("Task ID to get"),
|
id: z.string().describe('Task ID to get'),
|
||||||
file: z.string().optional().describe("Path to the tasks file"),
|
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||||
projectRoot: z
|
projectRoot: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.describe(
|
.describe(
|
||||||
"Root directory of the project (default: current working directory)"
|
'Root directory of the project (default: current working directory)'
|
||||||
),
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session, reportProgress }) => {
|
execute: async (args, { log, session, reportProgress }) => {
|
||||||
// Log the session right at the start of execute
|
// 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 {
|
try {
|
||||||
log.info(`Getting task details for ID: ${args.id}`);
|
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
|
||||||
|
|
||||||
let rootFolder = getProjectRootFromSession(session, log);
|
let rootFolder = getProjectRootFromSession(session, log);
|
||||||
|
|
||||||
@@ -64,29 +68,41 @@ export function registerShowTaskTool(server) {
|
|||||||
} else if (!rootFolder) {
|
} else if (!rootFolder) {
|
||||||
// Ensure we always have *some* root, even if session failed and args didn't provide one
|
// Ensure we always have *some* root, even if session failed and args didn't provide one
|
||||||
rootFolder = process.cwd();
|
rootFolder = process.cwd();
|
||||||
log.warn(`Session and args failed to provide root, using CWD: ${rootFolder}`);
|
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(`Attempting to use project root: ${rootFolder}`); // Log the final resolved root
|
||||||
|
|
||||||
log.info(`Root folder: ${rootFolder}`); // Log the final resolved root
|
log.info(`Root folder: ${rootFolder}`); // Log the final resolved root
|
||||||
const result = await showTaskDirect({
|
const result = await showTaskDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log);
|
},
|
||||||
|
log
|
||||||
|
);
|
||||||
|
|
||||||
if (result.success) {
|
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 {
|
} else {
|
||||||
log.error(`Failed to get task: ${result.error.message}`);
|
log.error(`Failed to get task: ${result.error.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use our custom processor function to remove allTasks from the response
|
// 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) {
|
} catch (error) {
|
||||||
log.error(`Error in get-task tool: ${error.message}\n${error.stack}`); // Add stack trace
|
log.error(`Error in get-task tool: ${error.message}\n${error.stack}`); // Add stack trace
|
||||||
return createErrorResponse(`Failed to get task: ${error.message}`);
|
return createErrorResponse(`Failed to get task: ${error.message}`);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool to get all tasks from Task Master
|
* Tool to get all tasks from Task Master
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { listTasksDirect } from "../core/task-master-core.js";
|
import { listTasksDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the getTasks tool with the MCP server
|
* Register the getTasks tool with the MCP server
|
||||||
@@ -17,21 +17,32 @@ import { listTasksDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerListTasksTool(server) {
|
export function registerListTasksTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "get_tasks",
|
name: 'get_tasks',
|
||||||
description: "Get all tasks from Task Master, optionally filtering by status and including subtasks.",
|
description:
|
||||||
|
'Get all tasks from Task Master, optionally filtering by status and including subtasks.',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
status: z.string().optional().describe("Filter tasks by status (e.g., 'pending', 'done')"),
|
status: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.describe("Filter tasks by status (e.g., 'pending', 'done')"),
|
||||||
withSubtasks: z
|
withSubtasks: z
|
||||||
.boolean()
|
.boolean()
|
||||||
.optional()
|
.optional()
|
||||||
.describe("Include subtasks nested within their parent tasks in the response"),
|
.describe(
|
||||||
file: z.string().optional().describe("Path to the tasks file (relative to project root or absolute)"),
|
'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
|
projectRoot: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.describe(
|
.describe(
|
||||||
"Root directory of the project (default: automatically detected from session or CWD)"
|
'Root directory of the project (default: automatically detected from session or CWD)'
|
||||||
),
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session, reportProgress }) => {
|
execute: async (args, { log, session, reportProgress }) => {
|
||||||
try {
|
try {
|
||||||
@@ -45,20 +56,25 @@ export function registerListTasksTool(server) {
|
|||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await listTasksDirect({
|
const result = await listTasksDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log/*, { reportProgress, mcpLog: log, session}*/);
|
},
|
||||||
|
log /*, { reportProgress, mcpLog: log, session}*/
|
||||||
|
);
|
||||||
|
|
||||||
// await reportProgress({ progress: 100 });
|
// 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');
|
return handleApiResult(result, log, 'Error getting tasks');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Error getting tasks: ${error.message}`);
|
log.error(`Error getting tasks: ${error.message}`);
|
||||||
return createErrorResponse(error.message);
|
return createErrorResponse(error.message);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,28 +3,28 @@
|
|||||||
* Export all Task Master CLI tools for MCP server
|
* Export all Task Master CLI tools for MCP server
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { registerListTasksTool } from "./get-tasks.js";
|
import { registerListTasksTool } from './get-tasks.js';
|
||||||
import logger from "../logger.js";
|
import logger from '../logger.js';
|
||||||
import { registerSetTaskStatusTool } from "./set-task-status.js";
|
import { registerSetTaskStatusTool } from './set-task-status.js';
|
||||||
import { registerParsePRDTool } from "./parse-prd.js";
|
import { registerParsePRDTool } from './parse-prd.js';
|
||||||
import { registerUpdateTool } from "./update.js";
|
import { registerUpdateTool } from './update.js';
|
||||||
import { registerUpdateTaskTool } from "./update-task.js";
|
import { registerUpdateTaskTool } from './update-task.js';
|
||||||
import { registerUpdateSubtaskTool } from "./update-subtask.js";
|
import { registerUpdateSubtaskTool } from './update-subtask.js';
|
||||||
import { registerGenerateTool } from "./generate.js";
|
import { registerGenerateTool } from './generate.js';
|
||||||
import { registerShowTaskTool } from "./get-task.js";
|
import { registerShowTaskTool } from './get-task.js';
|
||||||
import { registerNextTaskTool } from "./next-task.js";
|
import { registerNextTaskTool } from './next-task.js';
|
||||||
import { registerExpandTaskTool } from "./expand-task.js";
|
import { registerExpandTaskTool } from './expand-task.js';
|
||||||
import { registerAddTaskTool } from "./add-task.js";
|
import { registerAddTaskTool } from './add-task.js';
|
||||||
import { registerAddSubtaskTool } from "./add-subtask.js";
|
import { registerAddSubtaskTool } from './add-subtask.js';
|
||||||
import { registerRemoveSubtaskTool } from "./remove-subtask.js";
|
import { registerRemoveSubtaskTool } from './remove-subtask.js';
|
||||||
import { registerAnalyzeTool } from "./analyze.js";
|
import { registerAnalyzeTool } from './analyze.js';
|
||||||
import { registerClearSubtasksTool } from "./clear-subtasks.js";
|
import { registerClearSubtasksTool } from './clear-subtasks.js';
|
||||||
import { registerExpandAllTool } from "./expand-all.js";
|
import { registerExpandAllTool } from './expand-all.js';
|
||||||
import { registerRemoveDependencyTool } from "./remove-dependency.js";
|
import { registerRemoveDependencyTool } from './remove-dependency.js';
|
||||||
import { registerValidateDependenciesTool } from "./validate-dependencies.js";
|
import { registerValidateDependenciesTool } from './validate-dependencies.js';
|
||||||
import { registerFixDependenciesTool } from "./fix-dependencies.js";
|
import { registerFixDependenciesTool } from './fix-dependencies.js';
|
||||||
import { registerComplexityReportTool } from "./complexity-report.js";
|
import { registerComplexityReportTool } from './complexity-report.js';
|
||||||
import { registerAddDependencyTool } from "./add-dependency.js";
|
import { registerAddDependencyTool } from './add-dependency.js';
|
||||||
import { registerRemoveTaskTool } from './remove-task.js';
|
import { registerRemoveTaskTool } from './remove-task.js';
|
||||||
import { registerInitializeProjectTool } from './initialize-project.js';
|
import { registerInitializeProjectTool } from './initialize-project.js';
|
||||||
import { asyncOperationManager } from '../core/utils/async-manager.js';
|
import { asyncOperationManager } from '../core/utils/async-manager.js';
|
||||||
@@ -64,10 +64,8 @@ export function registerTaskMasterTools(server, asyncManager) {
|
|||||||
logger.error(`Error registering Task Master tools: ${error.message}`);
|
logger.error(`Error registering Task Master tools: ${error.message}`);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info('Registered Task Master MCP tools');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
registerTaskMasterTools,
|
registerTaskMasterTools
|
||||||
};
|
};
|
||||||
@@ -1,61 +1,93 @@
|
|||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import { execSync } from 'child_process';
|
import {
|
||||||
import { createContentResponse, createErrorResponse } from "./utils.js"; // Only need response creators
|
createContentResponse,
|
||||||
|
createErrorResponse,
|
||||||
|
handleApiResult
|
||||||
|
} from './utils.js';
|
||||||
|
import { initializeProjectDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
export function registerInitializeProjectTool(server) {
|
export function registerInitializeProjectTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "initialize_project", // snake_case for tool name
|
name: 'initialize_project',
|
||||||
description: "Initializes a new Task Master project structure in the current working directory by running 'task-master init'.",
|
description:
|
||||||
|
"Initializes a new Task Master project structure by calling the core initialization logic. Derives target directory from client session. If project details (name, description, author) are not provided, prompts the user or skips if 'yes' flag is true. DO NOT run without parameters.",
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
projectName: z.string().optional().describe("The name for the new project."),
|
projectName: z
|
||||||
projectDescription: z.string().optional().describe("A brief description for the project."),
|
.string()
|
||||||
projectVersion: z.string().optional().describe("The initial version for the project (e.g., '0.1.0')."),
|
.optional()
|
||||||
authorName: z.string().optional().describe("The author's name."),
|
.describe(
|
||||||
skipInstall: z.boolean().optional().default(false).describe("Skip installing dependencies automatically."),
|
'The name for the new project. If not provided, prompt the user for it.'
|
||||||
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."),
|
projectDescription: z
|
||||||
// projectRoot is not needed here as 'init' works on the current directory
|
.string()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
'A brief description for the project. If not provided, prompt the user for it.'
|
||||||
|
),
|
||||||
|
projectVersion: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
"The initial version for the project (e.g., '0.1.0'). User input not needed unless user requests to override."
|
||||||
|
),
|
||||||
|
authorName: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
"The author's name. User input not needed unless user requests to override."
|
||||||
|
),
|
||||||
|
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. User input not needed.'
|
||||||
|
),
|
||||||
|
yes: z
|
||||||
|
.boolean()
|
||||||
|
.optional()
|
||||||
|
.default(false)
|
||||||
|
.describe(
|
||||||
|
"Skip prompts and use default values or provided arguments. Use true if you wish to skip details like the project name, etc. If the project information required for the initialization is not available or provided by the user, prompt if the user wishes to provide them (name, description, author) or skip them. If the user wishes to skip, set the 'yes' flag to true and do not set any other parameters."
|
||||||
|
),
|
||||||
|
projectRoot: z
|
||||||
|
.string()
|
||||||
|
.describe(
|
||||||
|
'The root directory for the project. ALWAYS SET THIS TO THE PROJECT ROOT DIRECTORY. IF NOT SET, THE TOOL WILL NOT WORK.'
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log }) => { // Destructure context to get log
|
execute: async (args, context) => {
|
||||||
try {
|
const { log } = context;
|
||||||
log.info(`Executing initialize_project with args: ${JSON.stringify(args)}`);
|
const session = context.session;
|
||||||
|
|
||||||
// Construct the command arguments carefully
|
log.info(
|
||||||
// Using npx ensures it uses the locally installed version if available, or fetches it
|
'>>> Full Context Received by Tool:',
|
||||||
let command = 'npx task-master init';
|
JSON.stringify(context, null, 2)
|
||||||
const cliArgs = [];
|
);
|
||||||
if (args.projectName) cliArgs.push(`--name "${args.projectName.replace(/"/g, '\\"')}"`); // Escape quotes
|
log.info(`Context received in tool function: ${context}`);
|
||||||
if (args.projectDescription) cliArgs.push(`--description "${args.projectDescription.replace(/"/g, '\\"')}"`);
|
log.info(
|
||||||
if (args.projectVersion) cliArgs.push(`--version "${args.projectVersion.replace(/"/g, '\\"')}"`);
|
`Session received in tool function: ${session ? session : 'undefined'}`
|
||||||
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
|
|
||||||
);
|
);
|
||||||
|
|
||||||
} catch (error) {
|
try {
|
||||||
// Catch errors from execSync or timeouts
|
log.info(
|
||||||
const errorMessage = `Project initialization failed: ${error.message}`;
|
`Executing initialize_project tool with args: ${JSON.stringify(args)}`
|
||||||
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
|
const result = await initializeProjectDirect(args, log, { session });
|
||||||
return createErrorResponse(errorMessage, { details: errorDetails });
|
|
||||||
|
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 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool to find the next task to work on
|
* Tool to find the next task to work on
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { nextTaskDirect } from "../core/task-master-core.js";
|
import { nextTaskDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the next-task tool with the MCP server
|
* Register the next-task tool with the MCP server
|
||||||
@@ -17,16 +17,17 @@ import { nextTaskDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerNextTaskTool(server) {
|
export function registerNextTaskTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "next_task",
|
name: 'next_task',
|
||||||
description: "Find the next task to work on based on dependencies and status",
|
description:
|
||||||
|
'Find the next task to work on based on dependencies and status',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
file: z.string().optional().describe("Path to the tasks file"),
|
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||||
projectRoot: z
|
projectRoot: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.describe(
|
.describe(
|
||||||
"Root directory of the project (default: current working directory)"
|
'Root directory of the project (default: current working directory)'
|
||||||
),
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session, reportProgress }) => {
|
execute: async (args, { log, session, reportProgress }) => {
|
||||||
try {
|
try {
|
||||||
@@ -40,17 +41,24 @@ export function registerNextTaskTool(server) {
|
|||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await nextTaskDirect({
|
const result = await nextTaskDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log/*, { reportProgress, mcpLog: log, session}*/);
|
},
|
||||||
|
log /*, { reportProgress, mcpLog: log, session}*/
|
||||||
|
);
|
||||||
|
|
||||||
// await reportProgress({ progress: 100 });
|
// await reportProgress({ progress: 100 });
|
||||||
|
|
||||||
if (result.success) {
|
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 {
|
} 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');
|
return handleApiResult(result, log, 'Error finding next task');
|
||||||
@@ -58,6 +66,6 @@ export function registerNextTaskTool(server) {
|
|||||||
log.error(`Error in nextTask tool: ${error.message}`);
|
log.error(`Error in nextTask tool: ${error.message}`);
|
||||||
return createErrorResponse(error.message);
|
return createErrorResponse(error.message);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool to parse PRD document and generate tasks
|
* Tool to parse PRD document and generate tasks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { parsePRDDirect } from "../core/task-master-core.js";
|
import { parsePRDDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the parsePRD tool with the MCP server
|
* Register the parsePRD tool with the MCP server
|
||||||
@@ -17,40 +17,76 @@ import { parsePRDDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerParsePRDTool(server) {
|
export function registerParsePRDTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "parse_prd",
|
name: 'parse_prd',
|
||||||
description: "Parse a Product Requirements Document (PRD) or text file to automatically generate initial tasks.",
|
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.",
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
input: z.string().default("tasks/tasks.json").describe("Path to the PRD document file (relative to project root or absolute)"),
|
input: z
|
||||||
numTasks: z.string().optional().describe("Approximate number of top-level tasks to generate (default: 10)"),
|
.string()
|
||||||
output: z.string().optional().describe("Output path for tasks.json file (relative to project root or absolute, default: tasks/tasks.json)"),
|
.default('scripts/prd.txt')
|
||||||
force: z.boolean().optional().describe("Allow overwriting an existing tasks.json file."),
|
.describe('Absolute path to the PRD document file (.txt, .md, etc.)'),
|
||||||
projectRoot: z
|
numTasks: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.describe(
|
.describe(
|
||||||
"Root directory of the project (default: automatically detected from session or CWD)"
|
'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 absolute path for tasks.json file (default: tasks/tasks.json)'
|
||||||
|
),
|
||||||
|
force: z
|
||||||
|
.boolean()
|
||||||
|
.optional()
|
||||||
|
.describe('Allow overwriting an existing tasks.json file.'),
|
||||||
|
projectRoot: z
|
||||||
|
.string()
|
||||||
|
.describe(
|
||||||
|
'Absolute path to the root directory of the project. Required - ALWAYS SET THIS TO THE PROJECT ROOT DIRECTORY.'
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session }) => {
|
execute: async (args, { log, session }) => {
|
||||||
try {
|
try {
|
||||||
log.info(`Parsing PRD with args: ${JSON.stringify(args)}`);
|
log.info(`Parsing PRD with args: ${JSON.stringify(args)}`);
|
||||||
|
|
||||||
let rootFolder = getProjectRootFromSession(session, log);
|
// Make sure projectRoot is passed directly in args or derive from session
|
||||||
|
// We prioritize projectRoot from args over session-derived path
|
||||||
|
let rootFolder = args.projectRoot;
|
||||||
|
|
||||||
if (!rootFolder && args.projectRoot) {
|
// Only if args.projectRoot is undefined or null, try to get it from session
|
||||||
rootFolder = args.projectRoot;
|
if (!rootFolder) {
|
||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
log.warn(
|
||||||
|
'projectRoot not provided in args, attempting to derive from session'
|
||||||
|
);
|
||||||
|
rootFolder = getProjectRootFromSession(session, log);
|
||||||
|
|
||||||
|
if (!rootFolder) {
|
||||||
|
const errorMessage =
|
||||||
|
'Could not determine project root directory. Please provide projectRoot parameter.';
|
||||||
|
log.error(errorMessage);
|
||||||
|
return createErrorResponse(errorMessage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await parsePRDDirect({
|
log.info(`Using project root: ${rootFolder} for PRD parsing`);
|
||||||
|
|
||||||
|
const result = await parsePRDDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log, { session });
|
},
|
||||||
|
log,
|
||||||
|
{ session }
|
||||||
|
);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
log.info(`Successfully parsed PRD: ${result.data.message}`);
|
log.info(`Successfully parsed PRD: ${result.data.message}`);
|
||||||
} else {
|
} 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');
|
return handleApiResult(result, log, 'Error parsing PRD');
|
||||||
@@ -58,6 +94,6 @@ export function registerParsePRDTool(server) {
|
|||||||
log.error(`Error in parse-prd tool: ${error.message}`);
|
log.error(`Error in parse-prd tool: ${error.message}`);
|
||||||
return createErrorResponse(error.message);
|
return createErrorResponse(error.message);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool for removing a dependency from a task
|
* Tool for removing a dependency from a task
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { removeDependencyDirect } from "../core/task-master-core.js";
|
import { removeDependencyDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the removeDependency tool with the MCP server
|
* Register the removeDependency tool with the MCP server
|
||||||
@@ -17,17 +17,29 @@ import { removeDependencyDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerRemoveDependencyTool(server) {
|
export function registerRemoveDependencyTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "remove_dependency",
|
name: 'remove_dependency',
|
||||||
description: "Remove a dependency from a task",
|
description: 'Remove a dependency from a task',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
id: z.string().describe("Task ID to remove dependency from"),
|
id: z.string().describe('Task ID to remove dependency from'),
|
||||||
dependsOn: z.string().describe("Task ID to remove as a dependency"),
|
dependsOn: z.string().describe('Task ID to remove as a dependency'),
|
||||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
file: z
|
||||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
.string()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
'Absolute 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, reportProgress }) => {
|
execute: async (args, { log, session, reportProgress }) => {
|
||||||
try {
|
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 });
|
// await reportProgress({ progress: 0 });
|
||||||
|
|
||||||
let rootFolder = getProjectRootFromSession(session, log);
|
let rootFolder = getProjectRootFromSession(session, log);
|
||||||
@@ -37,10 +49,13 @@ export function registerRemoveDependencyTool(server) {
|
|||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await removeDependencyDirect({
|
const result = await removeDependencyDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log/*, { reportProgress, mcpLog: log, session}*/);
|
},
|
||||||
|
log /*, { reportProgress, mcpLog: log, session}*/
|
||||||
|
);
|
||||||
|
|
||||||
// await reportProgress({ progress: 100 });
|
// await reportProgress({ progress: 100 });
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool for removing subtasks from parent tasks
|
* Tool for removing subtasks from parent tasks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { removeSubtaskDirect } from "../core/task-master-core.js";
|
import { removeSubtaskDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the removeSubtask tool with the MCP server
|
* Register the removeSubtask tool with the MCP server
|
||||||
@@ -17,14 +17,36 @@ import { removeSubtaskDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerRemoveSubtaskTool(server) {
|
export function registerRemoveSubtaskTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "remove_subtask",
|
name: 'remove_subtask',
|
||||||
description: "Remove a subtask from its parent task",
|
description: 'Remove a subtask from its parent task',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
id: z.string().describe("Subtask ID to remove in format 'parentId.subtaskId' (required)"),
|
id: z
|
||||||
convert: z.boolean().optional().describe("Convert the subtask to a standalone task instead of deleting it"),
|
.string()
|
||||||
file: z.string().optional().describe("Path to the tasks file (default: tasks/tasks.json)"),
|
.describe(
|
||||||
skipGenerate: z.boolean().optional().describe("Skip regenerating task files"),
|
"Subtask ID to remove in format 'parentId.subtaskId' (required)"
|
||||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
),
|
||||||
|
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()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
'Root directory of the project (default: current working directory)'
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session, reportProgress }) => {
|
execute: async (args, { log, session, reportProgress }) => {
|
||||||
try {
|
try {
|
||||||
@@ -38,10 +60,13 @@ export function registerRemoveSubtaskTool(server) {
|
|||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await removeSubtaskDirect({
|
const result = await removeSubtaskDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log/*, { reportProgress, mcpLog: log, session}*/);
|
},
|
||||||
|
log /*, { reportProgress, mcpLog: log, session}*/
|
||||||
|
);
|
||||||
|
|
||||||
// await reportProgress({ progress: 100 });
|
// await reportProgress({ progress: 100 });
|
||||||
|
|
||||||
@@ -56,6 +81,6 @@ export function registerRemoveSubtaskTool(server) {
|
|||||||
log.error(`Error in removeSubtask tool: ${error.message}`);
|
log.error(`Error in removeSubtask tool: ${error.message}`);
|
||||||
return createErrorResponse(error.message);
|
return createErrorResponse(error.message);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool to remove a task by ID
|
* Tool to remove a task by ID
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { removeTaskDirect } from "../core/task-master-core.js";
|
import { removeTaskDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the remove-task tool with the MCP server
|
* Register the remove-task tool with the MCP server
|
||||||
@@ -17,18 +17,23 @@ import { removeTaskDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerRemoveTaskTool(server) {
|
export function registerRemoveTaskTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "remove_task",
|
name: 'remove_task',
|
||||||
description: "Remove a task or subtask permanently from the tasks list",
|
description: 'Remove a task or subtask permanently from the tasks list',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
id: z.string().describe("ID of the task or subtask to remove (e.g., '5' or '5.2')"),
|
id: z
|
||||||
file: z.string().optional().describe("Path to the tasks file"),
|
.string()
|
||||||
|
.describe("ID of the task or subtask to remove (e.g., '5' or '5.2')"),
|
||||||
|
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||||
projectRoot: z
|
projectRoot: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.describe(
|
.describe(
|
||||||
"Root directory of the project (default: current working directory)"
|
'Root directory of the project (default: current working directory)'
|
||||||
),
|
),
|
||||||
confirm: z.boolean().optional().describe("Whether to skip confirmation prompt (default: false)")
|
confirm: z
|
||||||
|
.boolean()
|
||||||
|
.optional()
|
||||||
|
.describe('Whether to skip confirmation prompt (default: false)')
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session }) => {
|
execute: async (args, { log, session }) => {
|
||||||
try {
|
try {
|
||||||
@@ -43,17 +48,22 @@ export function registerRemoveTaskTool(server) {
|
|||||||
} else if (!rootFolder) {
|
} else if (!rootFolder) {
|
||||||
// Ensure we have a default if nothing else works
|
// Ensure we have a default if nothing else works
|
||||||
rootFolder = process.cwd();
|
rootFolder = process.cwd();
|
||||||
log.warn(`Session and args failed to provide root, using CWD: ${rootFolder}`);
|
log.warn(
|
||||||
|
`Session and args failed to provide root, using CWD: ${rootFolder}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info(`Using project root: ${rootFolder}`);
|
log.info(`Using project root: ${rootFolder}`);
|
||||||
|
|
||||||
// Assume client has already handled confirmation if needed
|
// Assume client has already handled confirmation if needed
|
||||||
const result = await removeTaskDirect({
|
const result = await removeTaskDirect(
|
||||||
|
{
|
||||||
id: args.id,
|
id: args.id,
|
||||||
file: args.file,
|
file: args.file,
|
||||||
projectRoot: rootFolder
|
projectRoot: rootFolder
|
||||||
}, log);
|
},
|
||||||
|
log
|
||||||
|
);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
log.info(`Successfully removed task: ${args.id}`);
|
log.info(`Successfully removed task: ${args.id}`);
|
||||||
@@ -66,6 +76,6 @@ export function registerRemoveTaskTool(server) {
|
|||||||
log.error(`Error in remove-task tool: ${error.message}`);
|
log.error(`Error in remove-task tool: ${error.message}`);
|
||||||
return createErrorResponse(`Failed to remove task: ${error.message}`);
|
return createErrorResponse(`Failed to remove task: ${error.message}`);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool to set the status of a task
|
* Tool to set the status of a task
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { setTaskStatusDirect } from "../core/task-master-core.js";
|
import { setTaskStatusDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the setTaskStatus tool with the MCP server
|
* Register the setTaskStatus tool with the MCP server
|
||||||
@@ -17,22 +17,26 @@ import { setTaskStatusDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerSetTaskStatusTool(server) {
|
export function registerSetTaskStatusTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "set_task_status",
|
name: 'set_task_status',
|
||||||
description: "Set the status of one or more tasks or subtasks.",
|
description: 'Set the status of one or more tasks or subtasks.',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
id: z
|
id: z
|
||||||
.string()
|
.string()
|
||||||
.describe("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
|
status: z
|
||||||
.string()
|
.string()
|
||||||
.describe("New status to set (e.g., 'pending', 'done', 'in-progress', 'review', 'deferred', 'cancelled'."),
|
.describe(
|
||||||
file: z.string().optional().describe("Path to the tasks file"),
|
"New status to set (e.g., 'pending', 'done', 'in-progress', 'review', 'deferred', 'cancelled'."
|
||||||
|
),
|
||||||
|
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||||
projectRoot: z
|
projectRoot: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.describe(
|
.describe(
|
||||||
"Root directory of the project (default: automatically detected)"
|
'Root directory of the project (default: automatically detected)'
|
||||||
),
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session }) => {
|
execute: async (args, { log, session }) => {
|
||||||
try {
|
try {
|
||||||
@@ -47,24 +51,33 @@ export function registerSetTaskStatusTool(server) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call the direct function with the project root
|
// Call the direct function with the project root
|
||||||
const result = await setTaskStatusDirect({
|
const result = await setTaskStatusDirect(
|
||||||
|
{
|
||||||
...args,
|
...args,
|
||||||
projectRoot: rootFolder
|
projectRoot: rootFolder
|
||||||
}, log);
|
},
|
||||||
|
log
|
||||||
|
);
|
||||||
|
|
||||||
// Log the result
|
// Log the result
|
||||||
if (result.success) {
|
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 {
|
} 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
|
// Format and return the result
|
||||||
return handleApiResult(result, log, 'Error setting task status');
|
return handleApiResult(result, log, 'Error setting task status');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Error in setTaskStatus tool: ${error.message}`);
|
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,13 +3,13 @@
|
|||||||
* Tool to append additional information to a specific subtask
|
* Tool to append additional information to a specific subtask
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { updateSubtaskByIdDirect } from "../core/task-master-core.js";
|
import { updateSubtaskByIdDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the update-subtask tool with the MCP server
|
* Register the update-subtask tool with the MCP server
|
||||||
@@ -17,19 +17,27 @@ import { updateSubtaskByIdDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerUpdateSubtaskTool(server) {
|
export function registerUpdateSubtaskTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "update_subtask",
|
name: 'update_subtask',
|
||||||
description: "Appends additional information to a specific subtask without replacing existing content",
|
description:
|
||||||
|
'Appends additional information to a specific subtask without replacing existing content',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
id: z.string().describe("ID of the subtask to update in format \"parentId.subtaskId\" (e.g., \"5.2\")"),
|
id: z
|
||||||
prompt: z.string().describe("Information to add to the subtask"),
|
.string()
|
||||||
research: z.boolean().optional().describe("Use Perplexity AI for research-backed updates"),
|
.describe(
|
||||||
file: z.string().optional().describe("Path to the tasks file"),
|
'ID of the subtask to update in format "parentId.subtaskId" (e.g., "5.2")'
|
||||||
|
),
|
||||||
|
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'),
|
||||||
projectRoot: z
|
projectRoot: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.describe(
|
.describe(
|
||||||
"Root directory of the project (default: current working directory)"
|
'Root directory of the project (default: current working directory)'
|
||||||
),
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session }) => {
|
execute: async (args, { log, session }) => {
|
||||||
try {
|
try {
|
||||||
@@ -42,15 +50,21 @@ export function registerUpdateSubtaskTool(server) {
|
|||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await updateSubtaskByIdDirect({
|
const result = await updateSubtaskByIdDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log, { session });
|
},
|
||||||
|
log,
|
||||||
|
{ session }
|
||||||
|
);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
log.info(`Successfully updated subtask with ID ${args.id}`);
|
log.info(`Successfully updated subtask with ID ${args.id}`);
|
||||||
} else {
|
} 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');
|
return handleApiResult(result, log, 'Error updating subtask');
|
||||||
@@ -58,6 +72,6 @@ export function registerUpdateSubtaskTool(server) {
|
|||||||
log.error(`Error in update_subtask tool: ${error.message}`);
|
log.error(`Error in update_subtask tool: ${error.message}`);
|
||||||
return createErrorResponse(error.message);
|
return createErrorResponse(error.message);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool to update a single task by ID with new information
|
* Tool to update a single task by ID with new information
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { updateTaskByIdDirect } from "../core/task-master-core.js";
|
import { updateTaskByIdDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the update-task tool with the MCP server
|
* Register the update-task tool with the MCP server
|
||||||
@@ -17,19 +17,27 @@ import { updateTaskByIdDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerUpdateTaskTool(server) {
|
export function registerUpdateTaskTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "update_task",
|
name: 'update_task',
|
||||||
description: "Updates a single task by ID with new information or context provided in the prompt.",
|
description:
|
||||||
|
'Updates a single task by ID with new information or context provided in the prompt.',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
id: z.string().describe("ID of the task or subtask (e.g., '15', '15.2') to update"),
|
id: z
|
||||||
prompt: z.string().describe("New information or context to incorporate into the task"),
|
.string()
|
||||||
research: z.boolean().optional().describe("Use Perplexity AI for research-backed updates"),
|
.describe("ID of the task or subtask (e.g., '15', '15.2') to update"),
|
||||||
file: z.string().optional().describe("Path to the tasks file"),
|
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'),
|
||||||
projectRoot: z
|
projectRoot: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.describe(
|
.describe(
|
||||||
"Root directory of the project (default: current working directory)"
|
'Root directory of the project (default: current working directory)'
|
||||||
),
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session }) => {
|
execute: async (args, { log, session }) => {
|
||||||
try {
|
try {
|
||||||
@@ -42,15 +50,21 @@ export function registerUpdateTaskTool(server) {
|
|||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await updateTaskByIdDirect({
|
const result = await updateTaskByIdDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log, { session });
|
},
|
||||||
|
log,
|
||||||
|
{ session }
|
||||||
|
);
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
log.info(`Successfully updated task with ID ${args.id}`);
|
log.info(`Successfully updated task with ID ${args.id}`);
|
||||||
} else {
|
} 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');
|
return handleApiResult(result, log, 'Error updating task');
|
||||||
@@ -58,6 +72,6 @@ export function registerUpdateTaskTool(server) {
|
|||||||
log.error(`Error in update_task tool: ${error.message}`);
|
log.error(`Error in update_task tool: ${error.message}`);
|
||||||
return createErrorResponse(error.message);
|
return createErrorResponse(error.message);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool to update tasks based on new context/prompt
|
* Tool to update tasks based on new context/prompt
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { updateTasksDirect } from "../core/task-master-core.js";
|
import { updateTasksDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the update tool with the MCP server
|
* Register the update tool with the MCP server
|
||||||
@@ -17,19 +17,29 @@ import { updateTasksDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerUpdateTool(server) {
|
export function registerUpdateTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "update",
|
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.",
|
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({
|
parameters: z.object({
|
||||||
from: z.string().describe("Task ID from which to start updating (inclusive). IMPORTANT: This tool uses 'from', not 'id'"),
|
from: z
|
||||||
prompt: z.string().describe("Explanation of changes or new context to apply"),
|
.string()
|
||||||
research: z.boolean().optional().describe("Use Perplexity AI for research-backed updates"),
|
.describe(
|
||||||
file: z.string().optional().describe("Path to the tasks file"),
|
"Task ID from which to start updating (inclusive). IMPORTANT: This tool uses 'from', not 'id'"
|
||||||
|
),
|
||||||
|
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'),
|
||||||
projectRoot: z
|
projectRoot: z
|
||||||
.string()
|
.string()
|
||||||
.optional()
|
.optional()
|
||||||
.describe(
|
.describe(
|
||||||
"Root directory of the project (default: current working directory)"
|
'Root directory of the project (default: current working directory)'
|
||||||
),
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session }) => {
|
execute: async (args, { log, session }) => {
|
||||||
try {
|
try {
|
||||||
@@ -42,15 +52,23 @@ export function registerUpdateTool(server) {
|
|||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await updateTasksDirect({
|
const result = await updateTasksDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log, { session });
|
},
|
||||||
|
log,
|
||||||
|
{ session }
|
||||||
|
);
|
||||||
|
|
||||||
if (result.success) {
|
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 {
|
} 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');
|
return handleApiResult(result, log, 'Error updating tasks');
|
||||||
@@ -58,6 +76,6 @@ export function registerUpdateTool(server) {
|
|||||||
log.error(`Error in update tool: ${error.message}`);
|
log.error(`Error in update tool: ${error.message}`);
|
||||||
return createErrorResponse(error.message);
|
return createErrorResponse(error.message);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,13 @@
|
|||||||
* Utility functions for Task Master CLI integration
|
* Utility functions for Task Master CLI integration
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { spawnSync } from "child_process";
|
import { spawnSync } from 'child_process';
|
||||||
import path from "path";
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import { contextManager } from '../core/context-manager.js'; // Import the singleton
|
import { contextManager } from '../core/context-manager.js'; // Import the singleton
|
||||||
|
|
||||||
// Import path utilities to ensure consistent path resolution
|
// Import path utilities to ensure consistent path resolution
|
||||||
import { lastFoundProjectRoot, PROJECT_MARKERS } from '../core/utils/path-utils.js';
|
import { PROJECT_MARKERS } from '../core/utils/path-utils.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get normalized project root path
|
* Get normalized project root path
|
||||||
@@ -31,7 +31,9 @@ function getProjectRoot(projectRootRaw, log) {
|
|||||||
const absolutePath = path.isAbsolute(envRoot)
|
const absolutePath = path.isAbsolute(envRoot)
|
||||||
? envRoot
|
? envRoot
|
||||||
: path.resolve(process.cwd(), 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;
|
return absolutePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,23 +49,33 @@ function getProjectRoot(projectRootRaw, log) {
|
|||||||
|
|
||||||
// 3. If we have a last found project root from a tasks.json search, use that for consistency
|
// 3. If we have a last found project root from a tasks.json search, use that for consistency
|
||||||
if (lastFoundProjectRoot) {
|
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;
|
return lastFoundProjectRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Check if the current directory has any indicators of being a task-master project
|
// 4. Check if the current directory has any indicators of being a task-master project
|
||||||
const currentDir = process.cwd();
|
const currentDir = process.cwd();
|
||||||
if (PROJECT_MARKERS.some(marker => {
|
if (
|
||||||
|
PROJECT_MARKERS.some((marker) => {
|
||||||
const markerPath = path.join(currentDir, marker);
|
const markerPath = path.join(currentDir, marker);
|
||||||
return fs.existsSync(markerPath);
|
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;
|
return currentDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Default to current working directory but warn the user
|
// 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(
|
||||||
log.warn('Consider using --project-root to specify the correct project location or set TASK_MASTER_PROJECT_ROOT environment variable.');
|
`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;
|
return currentDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +88,8 @@ function getProjectRoot(projectRootRaw, log) {
|
|||||||
function getProjectRootFromSession(session, log) {
|
function getProjectRootFromSession(session, log) {
|
||||||
try {
|
try {
|
||||||
// Add detailed logging of session structure
|
// Add detailed logging of session structure
|
||||||
log.info(`Session object: ${JSON.stringify({
|
log.info(
|
||||||
|
`Session object: ${JSON.stringify({
|
||||||
hasSession: !!session,
|
hasSession: !!session,
|
||||||
hasRoots: !!session?.roots,
|
hasRoots: !!session?.roots,
|
||||||
rootsType: typeof session?.roots,
|
rootsType: typeof session?.roots,
|
||||||
@@ -88,7 +101,8 @@ function getProjectRootFromSession(session, log) {
|
|||||||
isRootsRootsArray: Array.isArray(session?.roots?.roots),
|
isRootsRootsArray: Array.isArray(session?.roots?.roots),
|
||||||
rootsRootsLength: session?.roots?.roots?.length,
|
rootsRootsLength: session?.roots?.roots?.length,
|
||||||
firstRootsRoot: session?.roots?.roots?.[0]
|
firstRootsRoot: session?.roots?.roots?.[0]
|
||||||
})}`);
|
})}`
|
||||||
|
);
|
||||||
|
|
||||||
// ALWAYS ensure we return a valid path for project root
|
// ALWAYS ensure we return a valid path for project root
|
||||||
const cwd = process.cwd();
|
const cwd = process.cwd();
|
||||||
@@ -125,9 +139,11 @@ function getProjectRootFromSession(session, log) {
|
|||||||
const projectRoot = serverPath.substring(0, mcpServerIndex - 1); // -1 to remove trailing slash
|
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
|
// 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, '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}`);
|
log.info(`Found project root from server path: ${projectRoot}`);
|
||||||
return projectRoot;
|
return projectRoot;
|
||||||
}
|
}
|
||||||
@@ -142,7 +158,9 @@ function getProjectRootFromSession(session, log) {
|
|||||||
const serverPath = process.argv[1];
|
const serverPath = process.argv[1];
|
||||||
if (serverPath && serverPath.includes('mcp-server')) {
|
if (serverPath && serverPath.includes('mcp-server')) {
|
||||||
const mcpServerIndex = serverPath.indexOf('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 "/"
|
// Only use cwd if it's not "/"
|
||||||
@@ -159,7 +177,12 @@ function getProjectRootFromSession(session, log) {
|
|||||||
* @param {Function} processFunction - Optional function to process successful result data
|
* @param {Function} processFunction - Optional function to process successful result data
|
||||||
* @returns {Object} - Standardized MCP response object
|
* @returns {Object} - Standardized MCP response object
|
||||||
*/
|
*/
|
||||||
function handleApiResult(result, log, errorPrefix = 'API error', processFunction = processMCPResponseData) {
|
function handleApiResult(
|
||||||
|
result,
|
||||||
|
log,
|
||||||
|
errorPrefix = 'API error',
|
||||||
|
processFunction = processMCPResponseData
|
||||||
|
) {
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
const errorMsg = result.error?.message || `Unknown ${errorPrefix}`;
|
const errorMsg = result.error?.message || `Unknown ${errorPrefix}`;
|
||||||
// Include cache status in error logs
|
// Include cache status in error logs
|
||||||
@@ -168,7 +191,9 @@ function handleApiResult(result, log, errorPrefix = 'API error', processFunction
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process the result data if needed
|
// 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 success including cache status
|
||||||
log.info(`Successfully completed operation. From cache: ${result.fromCache}`); // Add success log with cache status
|
log.info(`Successfully completed operation. From cache: ${result.fromCache}`); // Add success log with cache status
|
||||||
@@ -214,7 +239,7 @@ function executeTaskMasterCommand(
|
|||||||
|
|
||||||
// Common options for spawn
|
// Common options for spawn
|
||||||
const spawnOptions = {
|
const spawnOptions = {
|
||||||
encoding: "utf8",
|
encoding: 'utf8',
|
||||||
cwd: cwd,
|
cwd: cwd,
|
||||||
// Merge process.env with customEnv, giving precedence to customEnv
|
// Merge process.env with customEnv, giving precedence to customEnv
|
||||||
env: { ...process.env, ...(customEnv || {}) }
|
env: { ...process.env, ...(customEnv || {}) }
|
||||||
@@ -225,13 +250,13 @@ function executeTaskMasterCommand(
|
|||||||
|
|
||||||
// Execute the command using the global task-master CLI or local script
|
// Execute the command using the global task-master CLI or local script
|
||||||
// Try the global CLI first
|
// Try the global CLI first
|
||||||
let result = spawnSync("task-master", fullArgs, spawnOptions);
|
let result = spawnSync('task-master', fullArgs, spawnOptions);
|
||||||
|
|
||||||
// If global CLI is not available, try fallback to the local script
|
// If global CLI is not available, try fallback to the local script
|
||||||
if (result.error && result.error.code === "ENOENT") {
|
if (result.error && result.error.code === 'ENOENT') {
|
||||||
log.info("Global task-master not found, falling back to local script");
|
log.info('Global task-master not found, falling back to local script');
|
||||||
// Pass the same spawnOptions (including env) to the fallback
|
// Pass the same spawnOptions (including env) to the fallback
|
||||||
result = spawnSync("node", ["scripts/dev.js", ...fullArgs], spawnOptions);
|
result = spawnSync('node', ['scripts/dev.js', ...fullArgs], spawnOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.error) {
|
if (result.error) {
|
||||||
@@ -244,7 +269,7 @@ function executeTaskMasterCommand(
|
|||||||
? result.stderr.trim()
|
? result.stderr.trim()
|
||||||
: result.stdout
|
: result.stdout
|
||||||
? result.stdout.trim()
|
? result.stdout.trim()
|
||||||
: "Unknown error";
|
: 'Unknown error';
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Command failed with exit code ${result.status}: ${errorOutput}`
|
`Command failed with exit code ${result.status}: ${errorOutput}`
|
||||||
);
|
);
|
||||||
@@ -253,13 +278,13 @@ function executeTaskMasterCommand(
|
|||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
stdout: result.stdout,
|
stdout: result.stdout,
|
||||||
stderr: result.stderr,
|
stderr: result.stderr
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log.error(`Error executing task-master command: ${error.message}`);
|
log.error(`Error executing task-master command: ${error.message}`);
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
error: error.message,
|
error: error.message
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -301,9 +326,13 @@ async function getCachedOrExecute({ cacheKey, actionFn, log }) {
|
|||||||
const { fromCache, ...resultToCache } = result;
|
const { fromCache, ...resultToCache } = result;
|
||||||
contextManager.setCachedData(cacheKey, resultToCache);
|
contextManager.setCachedData(cacheKey, resultToCache);
|
||||||
} else if (!result.success) {
|
} 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 {
|
} 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
|
// Return the fresh result, indicating it wasn't from cache
|
||||||
@@ -320,7 +349,10 @@ async function getCachedOrExecute({ cacheKey, actionFn, log }) {
|
|||||||
* @param {string[]} fieldsToRemove - An array of field names to remove.
|
* @param {string[]} fieldsToRemove - An array of field names to remove.
|
||||||
* @returns {Object|Array} - The processed data with specified fields removed.
|
* @returns {Object|Array} - The processed data with specified fields removed.
|
||||||
*/
|
*/
|
||||||
function processMCPResponseData(taskOrData, fieldsToRemove = ['details', 'testStrategy']) {
|
function processMCPResponseData(
|
||||||
|
taskOrData,
|
||||||
|
fieldsToRemove = ['details', 'testStrategy']
|
||||||
|
) {
|
||||||
if (!taskOrData) {
|
if (!taskOrData) {
|
||||||
return taskOrData;
|
return taskOrData;
|
||||||
}
|
}
|
||||||
@@ -334,7 +366,7 @@ function processMCPResponseData(taskOrData, fieldsToRemove = ['details', 'testSt
|
|||||||
const processedTask = { ...task };
|
const processedTask = { ...task };
|
||||||
|
|
||||||
// Remove specified fields from the task
|
// Remove specified fields from the task
|
||||||
fieldsToRemove.forEach(field => {
|
fieldsToRemove.forEach((field) => {
|
||||||
delete processedTask[field];
|
delete processedTask[field];
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -353,14 +385,23 @@ function processMCPResponseData(taskOrData, fieldsToRemove = ['details', 'testSt
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Check if the input is a data structure containing a 'tasks' array (like from listTasks)
|
// 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 {
|
return {
|
||||||
...taskOrData, // Keep other potential fields like 'stats', 'filter'
|
...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)
|
// 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);
|
return processSingleTask(taskOrData);
|
||||||
}
|
}
|
||||||
// Check if the input is an array of tasks directly (less common but possible)
|
// Check if the input is an array of tasks directly (less common but possible)
|
||||||
@@ -382,11 +423,12 @@ function createContentResponse(content) {
|
|||||||
return {
|
return {
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
type: "text",
|
type: 'text',
|
||||||
text: typeof content === 'object' ?
|
text:
|
||||||
// Format JSON nicely with indentation
|
typeof content === 'object'
|
||||||
JSON.stringify(content, null, 2) :
|
? // Format JSON nicely with indentation
|
||||||
// Keep other content types as-is
|
JSON.stringify(content, null, 2)
|
||||||
|
: // Keep other content types as-is
|
||||||
String(content)
|
String(content)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -402,7 +444,7 @@ export function createErrorResponse(errorMessage) {
|
|||||||
return {
|
return {
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
type: "text",
|
type: 'text',
|
||||||
text: `Error: ${errorMessage}`
|
text: `Error: ${errorMessage}`
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -418,5 +460,5 @@ export {
|
|||||||
executeTaskMasterCommand,
|
executeTaskMasterCommand,
|
||||||
getCachedOrExecute,
|
getCachedOrExecute,
|
||||||
processMCPResponseData,
|
processMCPResponseData,
|
||||||
createContentResponse,
|
createContentResponse
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
* Tool for validating task dependencies
|
* Tool for validating task dependencies
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { z } from "zod";
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
handleApiResult,
|
handleApiResult,
|
||||||
createErrorResponse,
|
createErrorResponse,
|
||||||
getProjectRootFromSession
|
getProjectRootFromSession
|
||||||
} from "./utils.js";
|
} from './utils.js';
|
||||||
import { validateDependenciesDirect } from "../core/task-master-core.js";
|
import { validateDependenciesDirect } from '../core/task-master-core.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register the validateDependencies tool with the MCP server
|
* Register the validateDependencies tool with the MCP server
|
||||||
@@ -17,11 +17,17 @@ import { validateDependenciesDirect } from "../core/task-master-core.js";
|
|||||||
*/
|
*/
|
||||||
export function registerValidateDependenciesTool(server) {
|
export function registerValidateDependenciesTool(server) {
|
||||||
server.addTool({
|
server.addTool({
|
||||||
name: "validate_dependencies",
|
name: 'validate_dependencies',
|
||||||
description: "Check tasks for dependency issues (like circular references or links to non-existent tasks) without making changes.",
|
description:
|
||||||
|
'Check tasks for dependency issues (like circular references or links to non-existent tasks) without making changes.',
|
||||||
parameters: z.object({
|
parameters: z.object({
|
||||||
file: z.string().optional().describe("Path to the tasks file"),
|
file: z.string().optional().describe('Absolute path to the tasks file'),
|
||||||
projectRoot: z.string().optional().describe("Root directory of the project (default: current working directory)")
|
projectRoot: z
|
||||||
|
.string()
|
||||||
|
.optional()
|
||||||
|
.describe(
|
||||||
|
'Root directory of the project (default: current working directory)'
|
||||||
|
)
|
||||||
}),
|
}),
|
||||||
execute: async (args, { log, session, reportProgress }) => {
|
execute: async (args, { log, session, reportProgress }) => {
|
||||||
try {
|
try {
|
||||||
@@ -35,15 +41,21 @@ export function registerValidateDependenciesTool(server) {
|
|||||||
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
log.info(`Using project root from args as fallback: ${rootFolder}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await validateDependenciesDirect({
|
const result = await validateDependenciesDirect(
|
||||||
|
{
|
||||||
projectRoot: rootFolder,
|
projectRoot: rootFolder,
|
||||||
...args
|
...args
|
||||||
}, log, { reportProgress, mcpLog: log, session});
|
},
|
||||||
|
log,
|
||||||
|
{ reportProgress, mcpLog: log, session }
|
||||||
|
);
|
||||||
|
|
||||||
await reportProgress({ progress: 100 });
|
await reportProgress({ progress: 100 });
|
||||||
|
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
log.info(`Successfully validated dependencies: ${result.data.message}`);
|
log.info(
|
||||||
|
`Successfully validated dependencies: ${result.data.message}`
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
log.error(`Failed to validate dependencies: ${result.error.message}`);
|
log.error(`Failed to validate dependencies: ${result.error.message}`);
|
||||||
}
|
}
|
||||||
@@ -53,6 +65,6 @@ export function registerValidateDependenciesTool(server) {
|
|||||||
log.error(`Error in validateDependencies tool: ${error.message}`);
|
log.error(`Error in validateDependencies tool: ${error.message}`);
|
||||||
return createErrorResponse(error.message);
|
return createErrorResponse(error.message);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,9 @@ try {
|
|||||||
|
|
||||||
if (fs.existsSync(mcpPath)) {
|
if (fs.existsSync(mcpPath)) {
|
||||||
console.error('mcp.json file found');
|
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 {
|
} else {
|
||||||
console.error('mcp.json file not found');
|
console.error('mcp.json file not found');
|
||||||
}
|
}
|
||||||
@@ -27,7 +29,9 @@ try {
|
|||||||
|
|
||||||
// Check if env property exists
|
// Check if env property exists
|
||||||
if (config.env) {
|
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)
|
// Print each env var value (careful with sensitive values)
|
||||||
for (const [key, value] of Object.entries(config.env)) {
|
for (const [key, value] of Object.entries(config.env)) {
|
||||||
|
|||||||
51
package-lock.json
generated
51
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "task-master-ai",
|
"name": "task-master-ai",
|
||||||
"version": "0.10.0",
|
"version": "0.10.1",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "task-master-ai",
|
"name": "task-master-ai",
|
||||||
"version": "0.10.0",
|
"version": "0.10.1",
|
||||||
"license": "MIT WITH Commons-Clause",
|
"license": "MIT WITH Commons-Clause",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@anthropic-ai/sdk": "^0.39.0",
|
"@anthropic-ai/sdk": "^0.39.0",
|
||||||
@@ -31,9 +31,7 @@
|
|||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"task-master": "bin/task-master.js",
|
"task-master": "bin/task-master.js",
|
||||||
"task-master-init": "bin/task-master-init.js",
|
"task-master-mcp": "mcp-server/server.js"
|
||||||
"task-master-mcp": "mcp-server/server.js",
|
|
||||||
"task-master-mcp-server": "mcp-server/server.js"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@changesets/changelog-github": "^0.5.1",
|
"@changesets/changelog-github": "^0.5.1",
|
||||||
@@ -42,6 +40,7 @@
|
|||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-environment-node": "^29.7.0",
|
"jest-environment-node": "^29.7.0",
|
||||||
"mock-fs": "^5.5.0",
|
"mock-fs": "^5.5.0",
|
||||||
|
"prettier": "^3.5.3",
|
||||||
"supertest": "^7.1.0"
|
"supertest": "^7.1.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
@@ -608,6 +607,22 @@
|
|||||||
"semver": "^7.5.3"
|
"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": {
|
"node_modules/@changesets/apply-release-plan/node_modules/semver": {
|
||||||
"version": "7.7.1",
|
"version": "7.7.1",
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz",
|
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz",
|
||||||
@@ -930,6 +945,22 @@
|
|||||||
"prettier": "^2.7.1"
|
"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": {
|
"node_modules/@colors/colors": {
|
||||||
"version": "1.5.0",
|
"version": "1.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz",
|
||||||
@@ -6622,16 +6653,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/prettier": {
|
"node_modules/prettier": {
|
||||||
"version": "2.8.8",
|
"version": "3.5.3",
|
||||||
"resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz",
|
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.3.tgz",
|
||||||
"integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==",
|
"integrity": "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"bin": {
|
"bin": {
|
||||||
"prettier": "bin-prettier.js"
|
"prettier": "bin/prettier.cjs"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.13.0"
|
"node": ">=14"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/prettier/prettier?sponsor=1"
|
"url": "https://github.com/prettier/prettier?sponsor=1"
|
||||||
|
|||||||
13
package.json
13
package.json
@@ -6,9 +6,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": {
|
"bin": {
|
||||||
"task-master": "bin/task-master.js",
|
"task-master": "bin/task-master.js",
|
||||||
"task-master-init": "bin/task-master-init.js",
|
"task-master-mcp": "mcp-server/server.js"
|
||||||
"task-master-mcp": "mcp-server/server.js",
|
|
||||||
"task-master-mcp-server": "mcp-server/server.js"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node --experimental-vm-modules node_modules/.bin/jest",
|
"test": "node --experimental-vm-modules node_modules/.bin/jest",
|
||||||
@@ -17,11 +15,13 @@
|
|||||||
"test:coverage": "node --experimental-vm-modules node_modules/.bin/jest --coverage",
|
"test:coverage": "node --experimental-vm-modules node_modules/.bin/jest --coverage",
|
||||||
"prepare-package": "node scripts/prepare-package.js",
|
"prepare-package": "node scripts/prepare-package.js",
|
||||||
"prepublishOnly": "npm run prepare-package",
|
"prepublishOnly": "npm run prepare-package",
|
||||||
"prepare": "chmod +x bin/task-master.js bin/task-master-init.js mcp-server/server.js",
|
"prepare": "chmod +x bin/task-master.js mcp-server/server.js",
|
||||||
"changeset": "changeset",
|
"changeset": "changeset",
|
||||||
"release": "changeset publish",
|
"release": "changeset publish",
|
||||||
"inspector": "CLIENT_PORT=8888 SERVER_PORT=9000 npx @modelcontextprotocol/inspector node mcp-server/server.js",
|
"inspector": "npx @modelcontextprotocol/inspector node mcp-server/server.js",
|
||||||
"mcp-server": "node mcp-server/server.js"
|
"mcp-server": "node mcp-server/server.js",
|
||||||
|
"format-check": "prettier --check .",
|
||||||
|
"format": "prettier --write ."
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"claude",
|
"claude",
|
||||||
@@ -91,6 +91,7 @@
|
|||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-environment-node": "^29.7.0",
|
"jest-environment-node": "^29.7.0",
|
||||||
"mock-fs": "^5.5.0",
|
"mock-fs": "^5.5.0",
|
||||||
|
"prettier": "^3.5.3",
|
||||||
"supertest": "^7.1.0"
|
"supertest": "^7.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,11 @@ In an AI-driven development process—particularly with tools like [Cursor](http
|
|||||||
The script can be configured through environment variables in a `.env` file at the root of the project:
|
The script can be configured through environment variables in a `.env` file at the root of the project:
|
||||||
|
|
||||||
### Required Configuration
|
### Required Configuration
|
||||||
|
|
||||||
- `ANTHROPIC_API_KEY`: Your Anthropic API key for Claude
|
- `ANTHROPIC_API_KEY`: Your Anthropic API key for Claude
|
||||||
|
|
||||||
### Optional Configuration
|
### Optional Configuration
|
||||||
|
|
||||||
- `MODEL`: Specify which Claude model to use (default: "claude-3-7-sonnet-20250219")
|
- `MODEL`: Specify which Claude model to use (default: "claude-3-7-sonnet-20250219")
|
||||||
- `MAX_TOKENS`: Maximum tokens for model responses (default: 4000)
|
- `MAX_TOKENS`: Maximum tokens for model responses (default: 4000)
|
||||||
- `TEMPERATURE`: Temperature for model responses (default: 0.7)
|
- `TEMPERATURE`: Temperature for model responses (default: 0.7)
|
||||||
@@ -39,6 +41,7 @@ The script can be configured through environment variables in a `.env` file at t
|
|||||||
## How It Works
|
## How It Works
|
||||||
|
|
||||||
1. **`tasks.json`**:
|
1. **`tasks.json`**:
|
||||||
|
|
||||||
- A JSON file at the project root containing an array of tasks (each with `id`, `title`, `description`, `status`, etc.).
|
- A JSON file at the project root containing an array of tasks (each with `id`, `title`, `description`, `status`, etc.).
|
||||||
- The `meta` field can store additional info like the project's name, version, or reference to the PRD.
|
- The `meta` field can store additional info like the project's name, version, or reference to the PRD.
|
||||||
- Tasks can have `subtasks` for more detailed implementation steps.
|
- Tasks can have `subtasks` for more detailed implementation steps.
|
||||||
@@ -102,6 +105,7 @@ node scripts/dev.js update --file=custom-tasks.json --from=5 --prompt="Change da
|
|||||||
```
|
```
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
- The `--prompt` parameter is required and should explain the changes or new context
|
- The `--prompt` parameter is required and should explain the changes or new context
|
||||||
- Only tasks that aren't marked as 'done' will be updated
|
- Only tasks that aren't marked as 'done' will be updated
|
||||||
- Tasks with ID >= the specified --from value will be updated
|
- Tasks with ID >= the specified --from value will be updated
|
||||||
@@ -120,6 +124,7 @@ node scripts/dev.js update-task --id=4 --prompt="Use JWT for authentication" --r
|
|||||||
```
|
```
|
||||||
|
|
||||||
This command:
|
This command:
|
||||||
|
|
||||||
- Updates only the specified task rather than a range of tasks
|
- Updates only the specified task rather than a range of tasks
|
||||||
- Provides detailed validation with helpful error messages
|
- Provides detailed validation with helpful error messages
|
||||||
- Checks for required API keys when using research mode
|
- Checks for required API keys when using research mode
|
||||||
@@ -146,6 +151,7 @@ node scripts/dev.js set-status --id=1,2,3 --status=done
|
|||||||
```
|
```
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
- When marking a parent task as "done", all of its subtasks will automatically be marked as "done" as well
|
- When marking a parent task as "done", all of its subtasks will automatically be marked as "done" as well
|
||||||
- Common status values are 'done', 'pending', and 'deferred', but any string is accepted
|
- Common status values are 'done', 'pending', and 'deferred', but any string is accepted
|
||||||
- You can specify multiple task IDs by separating them with commas
|
- You can specify multiple task IDs by separating them with commas
|
||||||
@@ -195,6 +201,7 @@ node scripts/dev.js clear-subtasks --all
|
|||||||
```
|
```
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
- After clearing subtasks, task files are automatically regenerated
|
- After clearing subtasks, task files are automatically regenerated
|
||||||
- This is useful when you want to regenerate subtasks with a different approach
|
- This is useful when you want to regenerate subtasks with a different approach
|
||||||
- Can be combined with the `expand` command to immediately generate new subtasks
|
- Can be combined with the `expand` command to immediately generate new subtasks
|
||||||
@@ -210,6 +217,7 @@ The script integrates with two AI services:
|
|||||||
The Perplexity integration uses the OpenAI client to connect to Perplexity's API, which provides enhanced research capabilities for generating more informed subtasks. If the Perplexity API is unavailable or encounters an error, the script will automatically fall back to using Anthropic's Claude.
|
The Perplexity integration uses the OpenAI client to connect to Perplexity's API, which provides enhanced research capabilities for generating more informed subtasks. If the Perplexity API is unavailable or encounters an error, the script will automatically fall back to using Anthropic's Claude.
|
||||||
|
|
||||||
To use the Perplexity integration:
|
To use the Perplexity integration:
|
||||||
|
|
||||||
1. Obtain a Perplexity API key
|
1. Obtain a Perplexity API key
|
||||||
2. Add `PERPLEXITY_API_KEY` to your `.env` file
|
2. Add `PERPLEXITY_API_KEY` to your `.env` file
|
||||||
3. Optionally specify `PERPLEXITY_MODEL` in your `.env` file (default: "sonar-medium-online")
|
3. Optionally specify `PERPLEXITY_MODEL` in your `.env` file (default: "sonar-medium-online")
|
||||||
@@ -218,6 +226,7 @@ To use the Perplexity integration:
|
|||||||
## Logging
|
## Logging
|
||||||
|
|
||||||
The script supports different logging levels controlled by the `LOG_LEVEL` environment variable:
|
The script supports different logging levels controlled by the `LOG_LEVEL` environment variable:
|
||||||
|
|
||||||
- `debug`: Detailed information, typically useful for troubleshooting
|
- `debug`: Detailed information, typically useful for troubleshooting
|
||||||
- `info`: Confirmation that things are working as expected (default)
|
- `info`: Confirmation that things are working as expected (default)
|
||||||
- `warn`: Warning messages that don't prevent execution
|
- `warn`: Warning messages that don't prevent execution
|
||||||
@@ -240,17 +249,20 @@ node scripts/dev.js remove-dependency --id=<id> --depends-on=<id>
|
|||||||
These commands:
|
These commands:
|
||||||
|
|
||||||
1. **Allow precise dependency management**:
|
1. **Allow precise dependency management**:
|
||||||
|
|
||||||
- Add dependencies between tasks with automatic validation
|
- Add dependencies between tasks with automatic validation
|
||||||
- Remove dependencies when they're no longer needed
|
- Remove dependencies when they're no longer needed
|
||||||
- Update task files automatically after changes
|
- Update task files automatically after changes
|
||||||
|
|
||||||
2. **Include validation checks**:
|
2. **Include validation checks**:
|
||||||
|
|
||||||
- Prevent circular dependencies (a task depending on itself)
|
- Prevent circular dependencies (a task depending on itself)
|
||||||
- Prevent duplicate dependencies
|
- Prevent duplicate dependencies
|
||||||
- Verify that both tasks exist before adding/removing dependencies
|
- Verify that both tasks exist before adding/removing dependencies
|
||||||
- Check if dependencies exist before attempting to remove them
|
- Check if dependencies exist before attempting to remove them
|
||||||
|
|
||||||
3. **Provide clear feedback**:
|
3. **Provide clear feedback**:
|
||||||
|
|
||||||
- Success messages confirm when dependencies are added/removed
|
- Success messages confirm when dependencies are added/removed
|
||||||
- Error messages explain why operations failed (if applicable)
|
- Error messages explain why operations failed (if applicable)
|
||||||
|
|
||||||
@@ -275,6 +287,7 @@ node scripts/dev.js validate-dependencies --file=custom-tasks.json
|
|||||||
```
|
```
|
||||||
|
|
||||||
This command:
|
This command:
|
||||||
|
|
||||||
- Scans all tasks and subtasks for non-existent dependencies
|
- Scans all tasks and subtasks for non-existent dependencies
|
||||||
- Identifies potential self-dependencies (tasks referencing themselves)
|
- Identifies potential self-dependencies (tasks referencing themselves)
|
||||||
- Reports all found issues without modifying files
|
- Reports all found issues without modifying files
|
||||||
@@ -296,6 +309,7 @@ node scripts/dev.js fix-dependencies --file=custom-tasks.json
|
|||||||
```
|
```
|
||||||
|
|
||||||
This command:
|
This command:
|
||||||
|
|
||||||
1. **Validates all dependencies** across tasks and subtasks
|
1. **Validates all dependencies** across tasks and subtasks
|
||||||
2. **Automatically removes**:
|
2. **Automatically removes**:
|
||||||
- References to non-existent tasks and subtasks
|
- References to non-existent tasks and subtasks
|
||||||
@@ -333,6 +347,7 @@ node scripts/dev.js analyze-complexity --research
|
|||||||
```
|
```
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
- The command uses Claude to analyze each task's complexity (or Perplexity with --research flag)
|
- The command uses Claude to analyze each task's complexity (or Perplexity with --research flag)
|
||||||
- Tasks are scored on a scale of 1-10
|
- Tasks are scored on a scale of 1-10
|
||||||
- Each task receives a recommended number of subtasks based on DEFAULT_SUBTASKS configuration
|
- Each task receives a recommended number of subtasks based on DEFAULT_SUBTASKS configuration
|
||||||
@@ -357,12 +372,14 @@ node scripts/dev.js expand --id=8 --num=5 --prompt="Custom prompt"
|
|||||||
```
|
```
|
||||||
|
|
||||||
When a complexity report exists:
|
When a complexity report exists:
|
||||||
|
|
||||||
- The `expand` command will use the recommended subtask count from the report (unless overridden)
|
- The `expand` command will use the recommended subtask count from the report (unless overridden)
|
||||||
- It will use the tailored expansion prompt from the report (unless a custom prompt is provided)
|
- It will use the tailored expansion prompt from the report (unless a custom prompt is provided)
|
||||||
- When using `--all`, tasks are sorted by complexity score (highest first)
|
- When using `--all`, tasks are sorted by complexity score (highest first)
|
||||||
- The `--research` flag is preserved from the complexity analysis to expansion
|
- The `--research` flag is preserved from the complexity analysis to expansion
|
||||||
|
|
||||||
The output report structure is:
|
The output report structure is:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"meta": {
|
"meta": {
|
||||||
@@ -381,7 +398,7 @@ The output report structure is:
|
|||||||
"expansionPrompt": "Create subtasks that handle detecting...",
|
"expansionPrompt": "Create subtasks that handle detecting...",
|
||||||
"reasoning": "This task requires sophisticated logic...",
|
"reasoning": "This task requires sophisticated logic...",
|
||||||
"expansionCommand": "node scripts/dev.js expand --id=8 --num=6 --prompt=\"Create subtasks...\" --research"
|
"expansionCommand": "node scripts/dev.js expand --id=8 --num=6 --prompt=\"Create subtasks...\" --research"
|
||||||
},
|
}
|
||||||
// More tasks sorted by complexity score (highest first)
|
// More tasks sorted by complexity score (highest first)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -457,16 +474,19 @@ This command is particularly useful when you need to examine a specific task in
|
|||||||
The script now includes improved error handling throughout all commands:
|
The script now includes improved error handling throughout all commands:
|
||||||
|
|
||||||
1. **Detailed Validation**:
|
1. **Detailed Validation**:
|
||||||
|
|
||||||
- Required parameters (like task IDs and prompts) are validated early
|
- Required parameters (like task IDs and prompts) are validated early
|
||||||
- File existence is checked with customized errors for common scenarios
|
- File existence is checked with customized errors for common scenarios
|
||||||
- Parameter type conversion is handled with clear error messages
|
- Parameter type conversion is handled with clear error messages
|
||||||
|
|
||||||
2. **Contextual Error Messages**:
|
2. **Contextual Error Messages**:
|
||||||
|
|
||||||
- Task not found errors include suggestions to run the list command
|
- Task not found errors include suggestions to run the list command
|
||||||
- API key errors include reminders to check environment variables
|
- API key errors include reminders to check environment variables
|
||||||
- Invalid ID format errors show the expected format
|
- Invalid ID format errors show the expected format
|
||||||
|
|
||||||
3. **Command-Specific Help Displays**:
|
3. **Command-Specific Help Displays**:
|
||||||
|
|
||||||
- When validation fails, detailed help for the specific command is shown
|
- When validation fails, detailed help for the specific command is shown
|
||||||
- Help displays include usage examples and parameter descriptions
|
- Help displays include usage examples and parameter descriptions
|
||||||
- Formatted in clear, color-coded boxes with examples
|
- Formatted in clear, color-coded boxes with examples
|
||||||
@@ -481,11 +501,13 @@ The script now includes improved error handling throughout all commands:
|
|||||||
The script now automatically checks for updates without slowing down execution:
|
The script now automatically checks for updates without slowing down execution:
|
||||||
|
|
||||||
1. **Background Version Checking**:
|
1. **Background Version Checking**:
|
||||||
|
|
||||||
- Non-blocking version checks run in the background while commands execute
|
- Non-blocking version checks run in the background while commands execute
|
||||||
- Actual command execution isn't delayed by version checking
|
- Actual command execution isn't delayed by version checking
|
||||||
- Update notifications appear after command completion
|
- Update notifications appear after command completion
|
||||||
|
|
||||||
2. **Update Notifications**:
|
2. **Update Notifications**:
|
||||||
|
|
||||||
- When a newer version is available, a notification is displayed
|
- When a newer version is available, a notification is displayed
|
||||||
- Notifications include current version, latest version, and update command
|
- Notifications include current version, latest version, and update command
|
||||||
- Formatted in an attention-grabbing box with clear instructions
|
- Formatted in an attention-grabbing box with clear instructions
|
||||||
@@ -516,6 +538,7 @@ node scripts/dev.js add-subtask --parent=5 --title="Login API route" --skip-gene
|
|||||||
```
|
```
|
||||||
|
|
||||||
Key features:
|
Key features:
|
||||||
|
|
||||||
- Create new subtasks with detailed properties or convert existing tasks
|
- Create new subtasks with detailed properties or convert existing tasks
|
||||||
- Define dependencies between subtasks
|
- Define dependencies between subtasks
|
||||||
- Set custom status for new subtasks
|
- Set custom status for new subtasks
|
||||||
@@ -538,6 +561,7 @@ node scripts/dev.js remove-subtask --id=5.2 --skip-generate
|
|||||||
```
|
```
|
||||||
|
|
||||||
Key features:
|
Key features:
|
||||||
|
|
||||||
- Remove subtasks individually or in batches
|
- Remove subtasks individually or in batches
|
||||||
- Optionally convert subtasks to standalone tasks
|
- Optionally convert subtasks to standalone tasks
|
||||||
- Control whether task files are regenerated
|
- Control whether task files are regenerated
|
||||||
|
|||||||
641
scripts/init.js
641
scripts/init.js
@@ -1,5 +1,3 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task Master
|
* Task Master
|
||||||
* Copyright (c) 2025 Eyal Toledano, Ralph Khreish
|
* Copyright (c) 2025 Eyal Toledano, Ralph Khreish
|
||||||
@@ -15,8 +13,6 @@
|
|||||||
* For the full license text, see the LICENSE file in the root directory.
|
* For the full license text, see the LICENSE file in the root directory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
console.log('Starting task-master-ai...');
|
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
@@ -27,49 +23,27 @@ import chalk from 'chalk';
|
|||||||
import figlet from 'figlet';
|
import figlet from 'figlet';
|
||||||
import boxen from 'boxen';
|
import boxen from 'boxen';
|
||||||
import gradient from 'gradient-string';
|
import gradient from 'gradient-string';
|
||||||
import { Command } from 'commander';
|
import {
|
||||||
|
isSilentMode,
|
||||||
|
enableSilentMode,
|
||||||
|
disableSilentMode
|
||||||
|
} from './modules/utils.js';
|
||||||
|
|
||||||
// Debug information
|
// Only log if not in silent mode
|
||||||
|
if (!isSilentMode()) {
|
||||||
|
console.log('Starting task-master-ai...');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug information - only log if not in silent mode
|
||||||
|
if (!isSilentMode()) {
|
||||||
console.log('Node version:', process.version);
|
console.log('Node version:', process.version);
|
||||||
console.log('Current directory:', process.cwd());
|
console.log('Current directory:', process.cwd());
|
||||||
console.log('Script path:', import.meta.url);
|
console.log('Script path:', import.meta.url);
|
||||||
|
}
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = dirname(__filename);
|
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
|
// Define log levels
|
||||||
const LOG_LEVELS = {
|
const LOG_LEVELS = {
|
||||||
debug: 0,
|
debug: 0,
|
||||||
@@ -80,7 +54,9 @@ const LOG_LEVELS = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Get log level from environment or default to info
|
// Get log level from environment or default to info
|
||||||
const LOG_LEVEL = process.env.LOG_LEVEL ? 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
|
// Create a color gradient for the banner
|
||||||
const coolGradient = gradient(['#00b4d8', '#0077b6', '#03045e']);
|
const coolGradient = gradient(['#00b4d8', '#0077b6', '#03045e']);
|
||||||
@@ -88,6 +64,8 @@ const warmGradient = gradient(['#fb8b24', '#e36414', '#9a031e']);
|
|||||||
|
|
||||||
// Display a fancy banner
|
// Display a fancy banner
|
||||||
function displayBanner() {
|
function displayBanner() {
|
||||||
|
if (isSilentMode()) return;
|
||||||
|
|
||||||
console.clear();
|
console.clear();
|
||||||
const bannerText = figlet.textSync('Task Master AI', {
|
const bannerText = figlet.textSync('Task Master AI', {
|
||||||
font: 'Standard',
|
font: 'Standard',
|
||||||
@@ -98,14 +76,18 @@ function displayBanner() {
|
|||||||
console.log(coolGradient(bannerText));
|
console.log(coolGradient(bannerText));
|
||||||
|
|
||||||
// Add creator credit line below the banner
|
// 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,
|
padding: 1,
|
||||||
margin: { top: 0, bottom: 1 },
|
margin: { top: 0, bottom: 1 },
|
||||||
borderStyle: 'round',
|
borderStyle: 'round',
|
||||||
borderColor: 'cyan'
|
borderColor: 'cyan'
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Logging function with icons and colors
|
// Logging function with icons and colors
|
||||||
@@ -121,6 +103,8 @@ function log(level, ...args) {
|
|||||||
if (LOG_LEVELS[level] >= LOG_LEVEL) {
|
if (LOG_LEVELS[level] >= LOG_LEVEL) {
|
||||||
const icon = icons[level] || '';
|
const icon = icons[level] || '';
|
||||||
|
|
||||||
|
// Only output to console if not in silent mode
|
||||||
|
if (!isSilentMode()) {
|
||||||
if (level === 'error') {
|
if (level === 'error') {
|
||||||
console.error(icon, chalk.red(...args));
|
console.error(icon, chalk.red(...args));
|
||||||
} else if (level === 'warn') {
|
} else if (level === 'warn') {
|
||||||
@@ -133,6 +117,7 @@ function log(level, ...args) {
|
|||||||
console.log(icon, ...args);
|
console.log(icon, ...args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Write to debug log if DEBUG=true
|
// Write to debug log if DEBUG=true
|
||||||
if (process.env.DEBUG === 'true') {
|
if (process.env.DEBUG === 'true') {
|
||||||
@@ -167,13 +152,16 @@ function addShellAliases() {
|
|||||||
try {
|
try {
|
||||||
// Check if file exists
|
// Check if file exists
|
||||||
if (!fs.existsSync(shellConfigFile)) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if aliases already exist
|
// Check if aliases already exist
|
||||||
const configContent = fs.readFileSync(shellConfigFile, 'utf8');
|
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.');
|
log('info', 'Task Master aliases already exist in shell config.');
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -187,7 +175,11 @@ alias taskmaster='task-master'
|
|||||||
|
|
||||||
fs.appendFileSync(shellConfigFile, aliasBlock);
|
fs.appendFileSync(shellConfigFile, aliasBlock);
|
||||||
log('success', `Added Task Master aliases to ${shellConfigFile}`);
|
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;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -210,16 +202,40 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
|
|||||||
sourcePath = path.join(__dirname, '..', 'assets', 'scripts_README.md');
|
sourcePath = path.join(__dirname, '..', 'assets', 'scripts_README.md');
|
||||||
break;
|
break;
|
||||||
case 'dev_workflow.mdc':
|
case 'dev_workflow.mdc':
|
||||||
sourcePath = path.join(__dirname, '..', '.cursor', 'rules', 'dev_workflow.mdc');
|
sourcePath = path.join(
|
||||||
|
__dirname,
|
||||||
|
'..',
|
||||||
|
'.cursor',
|
||||||
|
'rules',
|
||||||
|
'dev_workflow.mdc'
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'taskmaster.mdc':
|
case 'taskmaster.mdc':
|
||||||
sourcePath = path.join(__dirname, '..', '.cursor', 'rules', 'taskmaster.mdc');
|
sourcePath = path.join(
|
||||||
|
__dirname,
|
||||||
|
'..',
|
||||||
|
'.cursor',
|
||||||
|
'rules',
|
||||||
|
'taskmaster.mdc'
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'cursor_rules.mdc':
|
case 'cursor_rules.mdc':
|
||||||
sourcePath = path.join(__dirname, '..', '.cursor', 'rules', 'cursor_rules.mdc');
|
sourcePath = path.join(
|
||||||
|
__dirname,
|
||||||
|
'..',
|
||||||
|
'.cursor',
|
||||||
|
'rules',
|
||||||
|
'cursor_rules.mdc'
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'self_improve.mdc':
|
case 'self_improve.mdc':
|
||||||
sourcePath = path.join(__dirname, '..', '.cursor', 'rules', 'self_improve.mdc');
|
sourcePath = path.join(
|
||||||
|
__dirname,
|
||||||
|
'..',
|
||||||
|
'.cursor',
|
||||||
|
'rules',
|
||||||
|
'self_improve.mdc'
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
case 'README-task-master.md':
|
case 'README-task-master.md':
|
||||||
sourcePath = path.join(__dirname, '..', 'README-task-master.md');
|
sourcePath = path.join(__dirname, '..', 'README-task-master.md');
|
||||||
@@ -258,12 +274,17 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
|
|||||||
if (filename === '.gitignore') {
|
if (filename === '.gitignore') {
|
||||||
log('info', `${targetPath} already exists, merging content...`);
|
log('info', `${targetPath} already exists, merging content...`);
|
||||||
const existingContent = fs.readFileSync(targetPath, 'utf8');
|
const existingContent = fs.readFileSync(targetPath, 'utf8');
|
||||||
const existingLines = new Set(existingContent.split('\n').map(line => line.trim()));
|
const existingLines = new Set(
|
||||||
const newLines = content.split('\n').filter(line => !existingLines.has(line.trim()));
|
existingContent.split('\n').map((line) => line.trim())
|
||||||
|
);
|
||||||
|
const newLines = content
|
||||||
|
.split('\n')
|
||||||
|
.filter((line) => !existingLines.has(line.trim()));
|
||||||
|
|
||||||
if (newLines.length > 0) {
|
if (newLines.length > 0) {
|
||||||
// Add a comment to separate the original content from our additions
|
// 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' +
|
'\n\n# Added by Claude Task Master\n' +
|
||||||
newLines.join('\n');
|
newLines.join('\n');
|
||||||
fs.writeFileSync(targetPath, updatedContent);
|
fs.writeFileSync(targetPath, updatedContent);
|
||||||
@@ -276,11 +297,15 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
|
|||||||
|
|
||||||
// Handle .windsurfrules - append the entire content
|
// Handle .windsurfrules - append the entire content
|
||||||
if (filename === '.windsurfrules') {
|
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');
|
const existingContent = fs.readFileSync(targetPath, 'utf8');
|
||||||
|
|
||||||
// Add a separator comment before appending our content
|
// 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' +
|
'\n\n# Added by Task Master - Development Workflow Rules\n\n' +
|
||||||
content;
|
content;
|
||||||
fs.writeFileSync(targetPath, updatedContent);
|
fs.writeFileSync(targetPath, updatedContent);
|
||||||
@@ -292,7 +317,9 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
|
|||||||
if (filename === 'package.json') {
|
if (filename === 'package.json') {
|
||||||
log('info', `${targetPath} already exists, merging dependencies...`);
|
log('info', `${targetPath} already exists, merging dependencies...`);
|
||||||
try {
|
try {
|
||||||
const existingPackageJson = JSON.parse(fs.readFileSync(targetPath, 'utf8'));
|
const existingPackageJson = JSON.parse(
|
||||||
|
fs.readFileSync(targetPath, 'utf8')
|
||||||
|
);
|
||||||
const newPackageJson = JSON.parse(content);
|
const newPackageJson = JSON.parse(content);
|
||||||
|
|
||||||
// Merge dependencies, preferring existing versions in case of conflicts
|
// Merge dependencies, preferring existing versions in case of conflicts
|
||||||
@@ -305,8 +332,9 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
|
|||||||
existingPackageJson.scripts = {
|
existingPackageJson.scripts = {
|
||||||
...existingPackageJson.scripts,
|
...existingPackageJson.scripts,
|
||||||
...Object.fromEntries(
|
...Object.fromEntries(
|
||||||
Object.entries(newPackageJson.scripts)
|
Object.entries(newPackageJson.scripts).filter(
|
||||||
.filter(([key]) => !existingPackageJson.scripts[key])
|
([key]) => !existingPackageJson.scripts[key]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -319,7 +347,10 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
|
|||||||
targetPath,
|
targetPath,
|
||||||
JSON.stringify(existingPackageJson, null, 2)
|
JSON.stringify(existingPackageJson, null, 2)
|
||||||
);
|
);
|
||||||
log('success', `Updated ${targetPath} with required dependencies and scripts`);
|
log(
|
||||||
|
'success',
|
||||||
|
`Updated ${targetPath} with required dependencies and scripts`
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log('error', `Failed to merge package.json: ${error.message}`);
|
log('error', `Failed to merge package.json: ${error.message}`);
|
||||||
// Fallback to writing a backup of the existing file and creating a new one
|
// Fallback to writing a backup of the existing file and creating a new one
|
||||||
@@ -327,7 +358,10 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
|
|||||||
fs.copyFileSync(targetPath, backupPath);
|
fs.copyFileSync(targetPath, backupPath);
|
||||||
log('info', `Created backup of existing package.json at ${backupPath}`);
|
log('info', `Created backup of existing package.json at ${backupPath}`);
|
||||||
fs.writeFileSync(targetPath, content);
|
fs.writeFileSync(targetPath, content);
|
||||||
log('warn', `Replaced ${targetPath} with new content (due to JSON parsing error)`);
|
log(
|
||||||
|
'warn',
|
||||||
|
`Replaced ${targetPath} with new content (due to JSON parsing error)`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -336,14 +370,23 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
|
|||||||
if (filename === 'README.md') {
|
if (filename === 'README.md') {
|
||||||
log('info', `${targetPath} already exists`);
|
log('info', `${targetPath} already exists`);
|
||||||
// Create a separate README file specifically for this project
|
// 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);
|
fs.writeFileSync(taskMasterReadmePath, content);
|
||||||
log('success', `Created ${taskMasterReadmePath} (preserved original README.md)`);
|
log(
|
||||||
|
'success',
|
||||||
|
`Created ${taskMasterReadmePath} (preserved original README.md)`
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For other files, warn and prompt before overwriting
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,24 +395,50 @@ function copyTemplateFile(templateName, targetPath, replacements = {}) {
|
|||||||
log('info', `Created file: ${targetPath}`);
|
log('info', `Created file: ${targetPath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Main function to initialize a new project
|
// Main function to initialize a new project (Now relies solely on passed options)
|
||||||
async function initializeProject(options = {}) {
|
async function initializeProject(options = {}) {
|
||||||
// Display the banner
|
// Receives options as argument
|
||||||
|
// Only display banner if not in silent mode
|
||||||
|
if (!isSilentMode()) {
|
||||||
displayBanner();
|
displayBanner();
|
||||||
|
}
|
||||||
|
|
||||||
// If options are provided, use them directly without prompting
|
// Debug logging only if not in silent mode
|
||||||
if (options.projectName && options.projectDescription) {
|
if (!isSilentMode()) {
|
||||||
const projectName = options.projectName;
|
console.log('===== DEBUG: INITIALIZE PROJECT OPTIONS RECEIVED =====');
|
||||||
const projectDescription = options.projectDescription;
|
console.log('Full options object:', JSON.stringify(options));
|
||||||
const projectVersion = options.projectVersion || '1.0.0';
|
console.log('options.yes:', options.yes);
|
||||||
const authorName = options.authorName || '';
|
console.log('options.name:', options.name);
|
||||||
|
console.log('==================================================');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if we should skip prompts based on the passed options
|
||||||
|
const skipPrompts = options.yes || (options.name && options.description);
|
||||||
|
if (!isSilentMode()) {
|
||||||
|
console.log('Skip prompts determined:', skipPrompts);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (skipPrompts) {
|
||||||
|
if (!isSilentMode()) {
|
||||||
|
console.log('SKIPPING PROMPTS - Using defaults or provided values');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use provided options or defaults
|
||||||
|
const projectName = options.name || 'task-master-project';
|
||||||
|
const projectDescription =
|
||||||
|
options.description || 'A project managed with Task Master AI';
|
||||||
|
const projectVersion = options.version || '0.1.0'; // Default from commands.js or here
|
||||||
|
const authorName = options.author || 'Vibe coder'; // Default if not provided
|
||||||
const dryRun = options.dryRun || false;
|
const dryRun = options.dryRun || false;
|
||||||
const skipInstall = options.skipInstall || false;
|
const skipInstall = options.skipInstall || false;
|
||||||
const addAliases = options.addAliases || false;
|
const addAliases = options.aliases || false;
|
||||||
|
|
||||||
if (dryRun) {
|
if (dryRun) {
|
||||||
log('info', 'DRY RUN MODE: No files will be modified');
|
log('info', 'DRY RUN MODE: No files will be modified');
|
||||||
log('info', `Would initialize project: ${projectName} (${projectVersion})`);
|
log(
|
||||||
|
'info',
|
||||||
|
`Would initialize project: ${projectName} (${projectVersion})`
|
||||||
|
);
|
||||||
log('info', `Description: ${projectDescription}`);
|
log('info', `Description: ${projectDescription}`);
|
||||||
log('info', `Author: ${authorName || 'Not specified'}`);
|
log('info', `Author: ${authorName || 'Not specified'}`);
|
||||||
log('info', 'Would create/update necessary project files');
|
log('info', 'Would create/update necessary project files');
|
||||||
@@ -388,61 +457,93 @@ async function initializeProject(options = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
createProjectStructure(projectName, projectDescription, projectVersion, authorName, skipInstall, addAliases);
|
// Create structure using determined values
|
||||||
return {
|
createProjectStructure(
|
||||||
projectName,
|
projectName,
|
||||||
projectDescription,
|
projectDescription,
|
||||||
projectVersion,
|
projectVersion,
|
||||||
authorName
|
authorName,
|
||||||
};
|
skipInstall,
|
||||||
}
|
addAliases
|
||||||
|
);
|
||||||
// Otherwise, prompt the user for input
|
} else {
|
||||||
// Create readline interface only when needed
|
// Prompting logic (only runs if skipPrompts is false)
|
||||||
|
log('info', 'Required options not provided, proceeding with prompts.');
|
||||||
const rl = readline.createInterface({
|
const rl = readline.createInterface({
|
||||||
input: process.stdin,
|
input: process.stdin,
|
||||||
output: process.stdout
|
output: process.stdout
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const projectName = await promptQuestion(rl, chalk.cyan('Enter project name: '));
|
// Prompt user for input...
|
||||||
const projectDescription = await promptQuestion(rl, chalk.cyan('Enter project description: '));
|
const projectName = await promptQuestion(
|
||||||
const projectVersionInput = await promptQuestion(rl, chalk.cyan('Enter project version (default: 1.0.0): '));
|
rl,
|
||||||
const authorName = await promptQuestion(rl, chalk.cyan('Enter your name: '));
|
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): ')
|
||||||
|
); // Use a default for prompt
|
||||||
|
const authorName = await promptQuestion(
|
||||||
|
rl,
|
||||||
|
chalk.cyan('Enter your name: ')
|
||||||
|
);
|
||||||
|
const addAliasesInput = await promptQuestion(
|
||||||
|
rl,
|
||||||
|
chalk.cyan('Add shell aliases for task-master? (Y/n): ')
|
||||||
|
);
|
||||||
|
const addAliasesPrompted = addAliasesInput.trim().toLowerCase() !== 'n';
|
||||||
|
const projectVersion = projectVersionInput.trim()
|
||||||
|
? projectVersionInput
|
||||||
|
: '1.0.0';
|
||||||
|
|
||||||
// Ask about shell aliases
|
// Confirm settings...
|
||||||
const addAliasesInput = await promptQuestion(rl, chalk.cyan('Add shell aliases for task-master? (Y/n): '));
|
|
||||||
const addAliases = addAliasesInput.trim().toLowerCase() !== 'n';
|
|
||||||
|
|
||||||
// Set default version if not provided
|
|
||||||
const projectVersion = projectVersionInput.trim() ? projectVersionInput : '1.0.0';
|
|
||||||
|
|
||||||
// Confirm settings
|
|
||||||
console.log('\nProject settings:');
|
console.log('\nProject settings:');
|
||||||
console.log(chalk.blue('Name:'), chalk.white(projectName));
|
console.log(chalk.blue('Name:'), chalk.white(projectName));
|
||||||
console.log(chalk.blue('Description:'), chalk.white(projectDescription));
|
console.log(chalk.blue('Description:'), chalk.white(projectDescription));
|
||||||
console.log(chalk.blue('Version:'), chalk.white(projectVersion));
|
console.log(chalk.blue('Version:'), chalk.white(projectVersion));
|
||||||
console.log(chalk.blue('Author:'), chalk.white(authorName || 'Not specified'));
|
console.log(
|
||||||
console.log(chalk.blue('Add shell aliases:'), chalk.white(addAliases ? 'Yes' : 'No'));
|
chalk.blue('Author:'),
|
||||||
|
chalk.white(authorName || 'Not specified')
|
||||||
|
);
|
||||||
|
console.log(
|
||||||
|
chalk.blue(
|
||||||
|
'Add shell aliases (so you can use "tm" instead of "task-master"):'
|
||||||
|
),
|
||||||
|
chalk.white(addAliasesPrompted ? 'Yes' : 'No')
|
||||||
|
);
|
||||||
|
|
||||||
const confirmInput = await promptQuestion(rl, chalk.yellow('\nDo you want to continue with these settings? (Y/n): '));
|
const confirmInput = await promptQuestion(
|
||||||
|
rl,
|
||||||
|
chalk.yellow('\nDo you want to continue with these settings? (Y/n): ')
|
||||||
|
);
|
||||||
const shouldContinue = confirmInput.trim().toLowerCase() !== 'n';
|
const shouldContinue = confirmInput.trim().toLowerCase() !== 'n';
|
||||||
|
|
||||||
// Close the readline interface
|
|
||||||
rl.close();
|
rl.close();
|
||||||
|
|
||||||
if (!shouldContinue) {
|
if (!shouldContinue) {
|
||||||
log('info', 'Project initialization cancelled by user');
|
log('info', 'Project initialization cancelled by user');
|
||||||
return null;
|
process.exit(0); // Exit if cancelled
|
||||||
|
return; // Added return for clarity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Still respect dryRun/skipInstall if passed initially even when prompting
|
||||||
const dryRun = options.dryRun || false;
|
const dryRun = options.dryRun || false;
|
||||||
const skipInstall = options.skipInstall || false;
|
const skipInstall = options.skipInstall || false;
|
||||||
|
|
||||||
if (dryRun) {
|
if (dryRun) {
|
||||||
log('info', 'DRY RUN MODE: No files will be modified');
|
log('info', 'DRY RUN MODE: No files will be modified');
|
||||||
|
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');
|
log('info', 'Would create/update necessary project files');
|
||||||
if (addAliases) {
|
if (addAliasesPrompted) {
|
||||||
log('info', 'Would add shell aliases for task-master');
|
log('info', 'Would add shell aliases for task-master');
|
||||||
}
|
}
|
||||||
if (!skipInstall) {
|
if (!skipInstall) {
|
||||||
@@ -457,19 +558,20 @@ async function initializeProject(options = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the project structure
|
// Create structure using prompted values, respecting initial options where relevant
|
||||||
createProjectStructure(projectName, projectDescription, projectVersion, authorName, skipInstall, addAliases);
|
createProjectStructure(
|
||||||
|
|
||||||
return {
|
|
||||||
projectName,
|
projectName,
|
||||||
projectDescription,
|
projectDescription,
|
||||||
projectVersion,
|
projectVersion,
|
||||||
authorName
|
authorName,
|
||||||
};
|
skipInstall, // Use value from initial options
|
||||||
|
addAliasesPrompted // Use value from prompt
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Make sure to close readline on error
|
|
||||||
rl.close();
|
rl.close();
|
||||||
throw error;
|
log('error', `Error during prompting: ${error.message}`); // Use log function
|
||||||
|
process.exit(1); // Exit on error during prompts
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,7 +585,14 @@ function promptQuestion(rl, question) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Function to create the project structure
|
// Function to create the project structure
|
||||||
function createProjectStructure(projectName, projectDescription, projectVersion, authorName, skipInstall, addAliases) {
|
function createProjectStructure(
|
||||||
|
projectName,
|
||||||
|
projectDescription,
|
||||||
|
projectVersion,
|
||||||
|
authorName,
|
||||||
|
skipInstall,
|
||||||
|
addAliases
|
||||||
|
) {
|
||||||
const targetDir = process.cwd();
|
const targetDir = process.cwd();
|
||||||
log('info', `Initializing project in ${targetDir}`);
|
log('info', `Initializing project in ${targetDir}`);
|
||||||
|
|
||||||
@@ -498,33 +607,32 @@ function createProjectStructure(projectName, projectDescription, projectVersion,
|
|||||||
version: projectVersion,
|
version: projectVersion,
|
||||||
description: projectDescription,
|
description: projectDescription,
|
||||||
author: authorName,
|
author: authorName,
|
||||||
type: "module",
|
type: 'module',
|
||||||
scripts: {
|
scripts: {
|
||||||
"dev": "node scripts/dev.js",
|
dev: 'node scripts/dev.js',
|
||||||
"list": "node scripts/dev.js list",
|
list: 'node scripts/dev.js list',
|
||||||
"generate": "node scripts/dev.js generate",
|
generate: 'node scripts/dev.js generate',
|
||||||
"parse-prd": "node scripts/dev.js parse-prd"
|
'parse-prd': 'node scripts/dev.js parse-prd'
|
||||||
},
|
},
|
||||||
dependencies: {
|
dependencies: {
|
||||||
"@anthropic-ai/sdk": "^0.39.0",
|
'@anthropic-ai/sdk': '^0.39.0',
|
||||||
"boxen": "^8.0.1",
|
boxen: '^8.0.1',
|
||||||
"chalk": "^4.1.2",
|
chalk: '^4.1.2',
|
||||||
"commander": "^11.1.0",
|
commander: '^11.1.0',
|
||||||
"cli-table3": "^0.6.5",
|
'cli-table3': '^0.6.5',
|
||||||
"cors": "^2.8.5",
|
cors: '^2.8.5',
|
||||||
"dotenv": "^16.3.1",
|
dotenv: '^16.3.1',
|
||||||
"express": "^4.21.2",
|
express: '^4.21.2',
|
||||||
"fastmcp": "^1.20.5",
|
fastmcp: '^1.20.5',
|
||||||
"figlet": "^1.8.0",
|
figlet: '^1.8.0',
|
||||||
"fuse.js": "^7.0.0",
|
'fuse.js': '^7.0.0',
|
||||||
"gradient-string": "^3.0.0",
|
'gradient-string': '^3.0.0',
|
||||||
"helmet": "^8.1.0",
|
helmet: '^8.1.0',
|
||||||
"inquirer": "^12.5.0",
|
inquirer: '^12.5.0',
|
||||||
"jsonwebtoken": "^9.0.2",
|
jsonwebtoken: '^9.0.2',
|
||||||
"lru-cache": "^10.2.0",
|
'lru-cache': '^10.2.0',
|
||||||
"openai": "^4.89.0",
|
openai: '^4.89.0',
|
||||||
"ora": "^8.2.0",
|
ora: '^8.2.0'
|
||||||
"task-master-ai": "^0.9.31"
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -533,7 +641,9 @@ function createProjectStructure(projectName, projectDescription, projectVersion,
|
|||||||
if (fs.existsSync(packageJsonPath)) {
|
if (fs.existsSync(packageJsonPath)) {
|
||||||
log('info', 'package.json already exists, merging content...');
|
log('info', 'package.json already exists, merging content...');
|
||||||
try {
|
try {
|
||||||
const existingPackageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
const existingPackageJson = JSON.parse(
|
||||||
|
fs.readFileSync(packageJsonPath, 'utf8')
|
||||||
|
);
|
||||||
|
|
||||||
// Preserve existing fields but add our required ones
|
// Preserve existing fields but add our required ones
|
||||||
const mergedPackageJson = {
|
const mergedPackageJson = {
|
||||||
@@ -541,15 +651,21 @@ function createProjectStructure(projectName, projectDescription, projectVersion,
|
|||||||
scripts: {
|
scripts: {
|
||||||
...existingPackageJson.scripts,
|
...existingPackageJson.scripts,
|
||||||
...Object.fromEntries(
|
...Object.fromEntries(
|
||||||
Object.entries(packageJson.scripts)
|
Object.entries(packageJson.scripts).filter(
|
||||||
.filter(([key]) => !existingPackageJson.scripts || !existingPackageJson.scripts[key])
|
([key]) =>
|
||||||
|
!existingPackageJson.scripts ||
|
||||||
|
!existingPackageJson.scripts[key]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
dependencies: {
|
dependencies: {
|
||||||
...existingPackageJson.dependencies || {},
|
...(existingPackageJson.dependencies || {}),
|
||||||
...Object.fromEntries(
|
...Object.fromEntries(
|
||||||
Object.entries(packageJson.dependencies)
|
Object.entries(packageJson.dependencies).filter(
|
||||||
.filter(([key]) => !existingPackageJson.dependencies || !existingPackageJson.dependencies[key])
|
([key]) =>
|
||||||
|
!existingPackageJson.dependencies ||
|
||||||
|
!existingPackageJson.dependencies[key]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -559,7 +675,10 @@ function createProjectStructure(projectName, projectDescription, projectVersion,
|
|||||||
mergedPackageJson.type = packageJson.type;
|
mergedPackageJson.type = packageJson.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(packageJsonPath, JSON.stringify(mergedPackageJson, null, 2));
|
fs.writeFileSync(
|
||||||
|
packageJsonPath,
|
||||||
|
JSON.stringify(mergedPackageJson, null, 2)
|
||||||
|
);
|
||||||
log('success', 'Updated package.json with required fields');
|
log('success', 'Updated package.json with required fields');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log('error', `Failed to merge package.json: ${error.message}`);
|
log('error', `Failed to merge package.json: ${error.message}`);
|
||||||
@@ -568,7 +687,10 @@ function createProjectStructure(projectName, projectDescription, projectVersion,
|
|||||||
fs.copyFileSync(packageJsonPath, backupPath);
|
fs.copyFileSync(packageJsonPath, backupPath);
|
||||||
log('info', `Created backup of existing package.json at ${backupPath}`);
|
log('info', `Created backup of existing package.json at ${backupPath}`);
|
||||||
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
||||||
log('warn', 'Created new package.json (backup of original file was created)');
|
log(
|
||||||
|
'warn',
|
||||||
|
'Created new package.json (backup of original file was created)'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If package.json doesn't exist, create it
|
// If package.json doesn't exist, create it
|
||||||
@@ -589,22 +711,38 @@ function createProjectStructure(projectName, projectDescription, projectVersion,
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Copy .env.example
|
// Copy .env.example
|
||||||
copyTemplateFile('env.example', path.join(targetDir, '.env.example'), replacements);
|
copyTemplateFile(
|
||||||
|
'env.example',
|
||||||
|
path.join(targetDir, '.env.example'),
|
||||||
|
replacements
|
||||||
|
);
|
||||||
|
|
||||||
// Copy .gitignore
|
// Copy .gitignore
|
||||||
copyTemplateFile('gitignore', path.join(targetDir, '.gitignore'));
|
copyTemplateFile('gitignore', path.join(targetDir, '.gitignore'));
|
||||||
|
|
||||||
// Copy dev_workflow.mdc
|
// 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
|
// 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
|
// 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
|
// 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
|
// Copy .windsurfrules
|
||||||
copyTemplateFile('windsurfrules', path.join(targetDir, '.windsurfrules'));
|
copyTemplateFile('windsurfrules', path.join(targetDir, '.windsurfrules'));
|
||||||
@@ -613,13 +751,23 @@ function createProjectStructure(projectName, projectDescription, projectVersion,
|
|||||||
copyTemplateFile('dev.js', path.join(targetDir, 'scripts', 'dev.js'));
|
copyTemplateFile('dev.js', path.join(targetDir, 'scripts', 'dev.js'));
|
||||||
|
|
||||||
// Copy scripts/README.md
|
// Copy scripts/README.md
|
||||||
copyTemplateFile('scripts_README.md', path.join(targetDir, 'scripts', 'README.md'));
|
copyTemplateFile(
|
||||||
|
'scripts_README.md',
|
||||||
|
path.join(targetDir, 'scripts', 'README.md')
|
||||||
|
);
|
||||||
|
|
||||||
// Copy example_prd.txt
|
// 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
|
// Create main README.md
|
||||||
copyTemplateFile('README-task-master.md', path.join(targetDir, 'README.md'), replacements);
|
copyTemplateFile(
|
||||||
|
'README-task-master.md',
|
||||||
|
path.join(targetDir, 'README.md'),
|
||||||
|
replacements
|
||||||
|
);
|
||||||
|
|
||||||
// Initialize git repository if git is available
|
// Initialize git repository if git is available
|
||||||
try {
|
try {
|
||||||
@@ -633,12 +781,16 @@ function createProjectStructure(projectName, projectDescription, projectVersion,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run npm install automatically
|
// Run npm install automatically
|
||||||
console.log(boxen(chalk.cyan('Installing dependencies...'), {
|
if (!isSilentMode()) {
|
||||||
|
console.log(
|
||||||
|
boxen(chalk.cyan('Installing dependencies...'), {
|
||||||
padding: 0.5,
|
padding: 0.5,
|
||||||
margin: 0.5,
|
margin: 0.5,
|
||||||
borderStyle: 'round',
|
borderStyle: 'round',
|
||||||
borderColor: 'blue'
|
borderColor: 'blue'
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!skipInstall) {
|
if (!skipInstall) {
|
||||||
@@ -653,16 +805,23 @@ function createProjectStructure(projectName, projectDescription, projectVersion,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Display success message
|
// Display success message
|
||||||
console.log(boxen(
|
if (!isSilentMode()) {
|
||||||
warmGradient.multiline(figlet.textSync('Success!', { font: 'Standard' })) +
|
console.log(
|
||||||
'\n' + chalk.green('Project initialized successfully!'),
|
boxen(
|
||||||
|
warmGradient.multiline(
|
||||||
|
figlet.textSync('Success!', { font: 'Standard' })
|
||||||
|
) +
|
||||||
|
'\n' +
|
||||||
|
chalk.green('Project initialized successfully!'),
|
||||||
{
|
{
|
||||||
padding: 1,
|
padding: 1,
|
||||||
margin: 1,
|
margin: 1,
|
||||||
borderStyle: 'double',
|
borderStyle: 'double',
|
||||||
borderColor: 'green'
|
borderColor: 'green'
|
||||||
}
|
}
|
||||||
));
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Add shell aliases if requested
|
// Add shell aliases if requested
|
||||||
if (addAliases) {
|
if (addAliases) {
|
||||||
@@ -670,19 +829,59 @@ function createProjectStructure(projectName, projectDescription, projectVersion,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Display next steps in a nice box
|
// Display next steps in a nice box
|
||||||
console.log(boxen(
|
if (!isSilentMode()) {
|
||||||
chalk.cyan.bold('Things you can now do:') + '\n\n' +
|
console.log(
|
||||||
chalk.white('1. ') + chalk.yellow('Rename .env.example to .env and add your ANTHROPIC_API_KEY and PERPLEXITY_API_KEY') + '\n' +
|
boxen(
|
||||||
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.cyan.bold('Things you can now do:') +
|
||||||
chalk.white('3. ') + chalk.yellow('Ask Cursor Agent to parse your PRD.txt and generate tasks') + '\n' +
|
'\n\n' +
|
||||||
chalk.white(' └─ ') + chalk.dim('You can also run ') + chalk.cyan('task-master parse-prd <your-prd-file.txt>') + '\n' +
|
chalk.white('1. ') +
|
||||||
chalk.white('4. ') + chalk.yellow('Ask Cursor to analyze the complexity of your tasks') + '\n' +
|
chalk.yellow(
|
||||||
chalk.white('5. ') + chalk.yellow('Ask Cursor which task is next to determine where to start') + '\n' +
|
'Rename .env.example to .env and add your ANTHROPIC_API_KEY and PERPLEXITY_API_KEY'
|
||||||
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' +
|
'\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('2. ') +
|
||||||
chalk.white('9. ') + chalk.green.bold('Ship it!') + '\n\n' +
|
chalk.yellow(
|
||||||
chalk.dim('* Review the README.md file to learn how to use other commands via Cursor Agent.'),
|
'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,
|
padding: 1,
|
||||||
margin: 1,
|
margin: 1,
|
||||||
@@ -691,7 +890,9 @@ function createProjectStructure(projectName, projectDescription, projectVersion,
|
|||||||
title: 'Getting Started',
|
title: 'Getting Started',
|
||||||
titleAlignment: 'center'
|
titleAlignment: 'center'
|
||||||
}
|
}
|
||||||
));
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to setup MCP configuration for Cursor integration
|
// Function to setup MCP configuration for Cursor integration
|
||||||
@@ -706,21 +907,18 @@ function setupMCPConfiguration(targetDir, projectName) {
|
|||||||
|
|
||||||
// New MCP config to be added - references the installed package
|
// New MCP config to be added - references the installed package
|
||||||
const newMCPServer = {
|
const newMCPServer = {
|
||||||
"task-master-ai": {
|
'task-master-ai': {
|
||||||
"command": "npx",
|
command: 'npx',
|
||||||
"args": [
|
args: ['-y', 'task-master-mcp'],
|
||||||
"-y",
|
env: {
|
||||||
"task-master-mcp-server"
|
ANTHROPIC_API_KEY: '%ANTHROPIC_API_KEY%',
|
||||||
],
|
PERPLEXITY_API_KEY: '%PERPLEXITY_API_KEY%',
|
||||||
"env": {
|
MODEL: 'claude-3-7-sonnet-20250219',
|
||||||
"ANTHROPIC_API_KEY": "%ANTHROPIC_API_KEY%",
|
PERPLEXITY_MODEL: 'sonar-pro',
|
||||||
"PERPLEXITY_API_KEY": "%PERPLEXITY_API_KEY%",
|
MAX_TOKENS: 64000,
|
||||||
"MODEL": "claude-3-7-sonnet-20250219",
|
TEMPERATURE: 0.3,
|
||||||
"PERPLEXITY_MODEL": "sonar-pro",
|
DEFAULT_SUBTASKS: 5,
|
||||||
"MAX_TOKENS": 64000,
|
DEFAULT_PRIORITY: 'medium'
|
||||||
"TEMPERATURE": 0.3,
|
|
||||||
"DEFAULT_SUBTASKS": 5,
|
|
||||||
"DEFAULT_PRIORITY": "medium"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -738,18 +936,18 @@ function setupMCPConfiguration(targetDir, projectName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the task-master-ai server if it doesn't exist
|
// Add the task-master-ai server if it doesn't exist
|
||||||
if (!mcpConfig.mcpServers["task-master-ai"]) {
|
if (!mcpConfig.mcpServers['task-master-ai']) {
|
||||||
mcpConfig.mcpServers["task-master-ai"] = newMCPServer["task-master-ai"];
|
mcpConfig.mcpServers['task-master-ai'] = newMCPServer['task-master-ai'];
|
||||||
log('info', 'Added task-master-ai server to existing MCP configuration');
|
log(
|
||||||
|
'info',
|
||||||
|
'Added task-master-ai server to existing MCP configuration'
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
log('info', 'task-master-ai server already configured in mcp.json');
|
log('info', 'task-master-ai server already configured in mcp.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the updated configuration
|
// Write the updated configuration
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 4));
|
||||||
mcpJsonPath,
|
|
||||||
JSON.stringify(mcpConfig, null, 4)
|
|
||||||
);
|
|
||||||
log('success', 'Updated MCP configuration file');
|
log('success', 'Updated MCP configuration file');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log('error', `Failed to update MCP configuration: ${error.message}`);
|
log('error', `Failed to update MCP configuration: ${error.message}`);
|
||||||
@@ -762,16 +960,19 @@ function setupMCPConfiguration(targetDir, projectName) {
|
|||||||
|
|
||||||
// Create new configuration
|
// Create new configuration
|
||||||
const newMCPConfig = {
|
const newMCPConfig = {
|
||||||
"mcpServers": newMCPServer
|
mcpServers: newMCPServer
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.writeFileSync(mcpJsonPath, JSON.stringify(newMCPConfig, null, 4));
|
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 {
|
} else {
|
||||||
// If mcp.json doesn't exist, create it
|
// If mcp.json doesn't exist, create it
|
||||||
const newMCPConfig = {
|
const newMCPConfig = {
|
||||||
"mcpServers": newMCPServer
|
mcpServers: newMCPServer
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.writeFileSync(mcpJsonPath, JSON.stringify(newMCPConfig, null, 4));
|
fs.writeFileSync(mcpJsonPath, JSON.stringify(newMCPConfig, null, 4));
|
||||||
@@ -782,53 +983,5 @@ function setupMCPConfiguration(targetDir, projectName) {
|
|||||||
log('info', 'MCP server will use the installed task-master-ai package');
|
log('info', 'MCP server will use the installed task-master-ai package');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the initialization if this script is executed directly
|
// Ensure necessary functions are exported
|
||||||
// The original check doesn't work with npx and global commands
|
export { initializeProject, log }; // Only export what's needed by commands.js
|
||||||
// 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,11 +34,13 @@ let perplexity = null;
|
|||||||
function getPerplexityClient() {
|
function getPerplexityClient() {
|
||||||
if (!perplexity) {
|
if (!perplexity) {
|
||||||
if (!process.env.PERPLEXITY_API_KEY) {
|
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({
|
perplexity = new OpenAI({
|
||||||
apiKey: process.env.PERPLEXITY_API_KEY,
|
apiKey: process.env.PERPLEXITY_API_KEY,
|
||||||
baseURL: 'https://api.perplexity.ai',
|
baseURL: 'https://api.perplexity.ai'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return perplexity;
|
return perplexity;
|
||||||
@@ -85,13 +87,18 @@ function getAvailableAIModel(options = {}) {
|
|||||||
// Last resort: Use Claude even if overloaded (might fail)
|
// Last resort: Use Claude even if overloaded (might fail)
|
||||||
if (process.env.ANTHROPIC_API_KEY) {
|
if (process.env.ANTHROPIC_API_KEY) {
|
||||||
if (claudeOverloaded) {
|
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 };
|
return { type: 'claude', client: anthropic };
|
||||||
}
|
}
|
||||||
|
|
||||||
// No models available
|
// 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.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -144,7 +151,15 @@ function handleClaudeError(error) {
|
|||||||
* @param {Object} modelConfig - Model configuration (optional)
|
* @param {Object} modelConfig - Model configuration (optional)
|
||||||
* @returns {Object} Claude's response
|
* @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 {
|
try {
|
||||||
log('info', 'Calling Claude...');
|
log('info', 'Calling Claude...');
|
||||||
|
|
||||||
@@ -215,16 +230,28 @@ Important: Your response must be valid JSON only, with no additional explanation
|
|||||||
log('error', userMessage);
|
log('error', userMessage);
|
||||||
|
|
||||||
// Retry logic for certain errors
|
// Retry logic for certain errors
|
||||||
if (retryCount < 2 && (
|
if (
|
||||||
error.error?.type === 'overloaded_error' ||
|
retryCount < 2 &&
|
||||||
|
(error.error?.type === 'overloaded_error' ||
|
||||||
error.error?.type === 'rate_limit_error' ||
|
error.error?.type === 'rate_limit_error' ||
|
||||||
error.message?.toLowerCase().includes('timeout') ||
|
error.message?.toLowerCase().includes('timeout') ||
|
||||||
error.message?.toLowerCase().includes('network')
|
error.message?.toLowerCase().includes('network'))
|
||||||
)) {
|
) {
|
||||||
const waitTime = (retryCount + 1) * 5000; // 5s, then 10s
|
const waitTime = (retryCount + 1) * 5000; // 5s, then 10s
|
||||||
log('info', `Waiting ${waitTime/1000} seconds before retry ${retryCount + 1}/2...`);
|
log(
|
||||||
await new Promise(resolve => setTimeout(resolve, waitTime));
|
'info',
|
||||||
return await callClaude(prdContent, prdPath, numTasks, retryCount + 1, { reportProgress, mcpLog, session }, aiClient, modelConfig);
|
`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 {
|
} else {
|
||||||
console.error(chalk.red(userMessage));
|
console.error(chalk.red(userMessage));
|
||||||
if (CONFIG.debug) {
|
if (CONFIG.debug) {
|
||||||
@@ -250,7 +277,16 @@ Important: Your response must be valid JSON only, with no additional explanation
|
|||||||
* @param {Object} modelConfig - Model configuration (optional)
|
* @param {Object} modelConfig - Model configuration (optional)
|
||||||
* @returns {Object} Claude's response
|
* @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
|
// Determine output format based on mcpLog presence
|
||||||
const outputFormat = mcpLog ? 'json' : 'text';
|
const outputFormat = mcpLog ? 'json' : 'text';
|
||||||
|
|
||||||
@@ -270,16 +306,23 @@ async function handleStreamingRequest(prdContent, prdPath, numTasks, maxTokens,
|
|||||||
loadingIndicator = startLoadingIndicator('Generating tasks from PRD...');
|
loadingIndicator = startLoadingIndicator('Generating tasks from PRD...');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reportProgress) { await reportProgress({ progress: 0 }); }
|
if (reportProgress) {
|
||||||
|
await reportProgress({ progress: 0 });
|
||||||
|
}
|
||||||
let responseText = '';
|
let responseText = '';
|
||||||
let streamingInterval = null;
|
let streamingInterval = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Use streaming for handling large responses
|
// Use streaming for handling large responses
|
||||||
const stream = await (aiClient || anthropic).messages.create({
|
const stream = await (aiClient || anthropic).messages.create({
|
||||||
model: modelConfig?.model || session?.env?.ANTHROPIC_MODEL || CONFIG.model,
|
model:
|
||||||
max_tokens: modelConfig?.maxTokens || session?.env?.MAX_TOKENS || maxTokens,
|
modelConfig?.model || session?.env?.ANTHROPIC_MODEL || CONFIG.model,
|
||||||
temperature: modelConfig?.temperature || session?.env?.TEMPERATURE || CONFIG.temperature,
|
max_tokens:
|
||||||
|
modelConfig?.maxTokens || session?.env?.MAX_TOKENS || maxTokens,
|
||||||
|
temperature:
|
||||||
|
modelConfig?.temperature ||
|
||||||
|
session?.env?.TEMPERATURE ||
|
||||||
|
CONFIG.temperature,
|
||||||
system: systemPrompt,
|
system: systemPrompt,
|
||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
@@ -296,7 +339,9 @@ async function handleStreamingRequest(prdContent, prdPath, numTasks, maxTokens,
|
|||||||
const readline = await import('readline');
|
const readline = await import('readline');
|
||||||
streamingInterval = setInterval(() => {
|
streamingInterval = setInterval(() => {
|
||||||
readline.cursorTo(process.stdout, 0);
|
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;
|
dotCount = (dotCount + 1) % 4;
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
@@ -307,10 +352,12 @@ async function handleStreamingRequest(prdContent, prdPath, numTasks, maxTokens,
|
|||||||
responseText += chunk.delta.text;
|
responseText += chunk.delta.text;
|
||||||
}
|
}
|
||||||
if (reportProgress) {
|
if (reportProgress) {
|
||||||
await reportProgress({ progress: (responseText.length / maxTokens) * 100 });
|
await reportProgress({
|
||||||
|
progress: (responseText.length / maxTokens) * 100
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (mcpLog) {
|
if (mcpLog) {
|
||||||
mcpLog.info(`Progress: ${responseText.length / maxTokens * 100}%`);
|
mcpLog.info(`Progress: ${(responseText.length / maxTokens) * 100}%`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,10 +368,20 @@ async function handleStreamingRequest(prdContent, prdPath, numTasks, maxTokens,
|
|||||||
stopLoadingIndicator(loadingIndicator);
|
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
|
// 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) {
|
} catch (error) {
|
||||||
if (streamingInterval) clearInterval(streamingInterval);
|
if (streamingInterval) clearInterval(streamingInterval);
|
||||||
|
|
||||||
@@ -360,7 +417,14 @@ async function handleStreamingRequest(prdContent, prdPath, numTasks, maxTokens,
|
|||||||
* @param {Object} options - Options object containing mcpLog etc.
|
* @param {Object} options - Options object containing mcpLog etc.
|
||||||
* @returns {Object} Processed response
|
* @returns {Object} Processed response
|
||||||
*/
|
*/
|
||||||
function processClaudeResponse(textContent, numTasks, retryCount, prdContent, prdPath, options = {}) {
|
function processClaudeResponse(
|
||||||
|
textContent,
|
||||||
|
numTasks,
|
||||||
|
retryCount,
|
||||||
|
prdContent,
|
||||||
|
prdPath,
|
||||||
|
options = {}
|
||||||
|
) {
|
||||||
const { mcpLog } = options;
|
const { mcpLog } = options;
|
||||||
|
|
||||||
// Determine output format based on mcpLog presence
|
// Determine output format based on mcpLog presence
|
||||||
@@ -395,13 +459,16 @@ function processClaudeResponse(textContent, numTasks, retryCount, prdContent, pr
|
|||||||
|
|
||||||
// Ensure we have the correct number of tasks
|
// Ensure we have the correct number of tasks
|
||||||
if (parsedData.tasks.length !== numTasks) {
|
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
|
// Add metadata if missing
|
||||||
if (!parsedData.metadata) {
|
if (!parsedData.metadata) {
|
||||||
parsedData.metadata = {
|
parsedData.metadata = {
|
||||||
projectName: "PRD Implementation",
|
projectName: 'PRD Implementation',
|
||||||
totalTasks: parsedData.tasks.length,
|
totalTasks: parsedData.tasks.length,
|
||||||
sourceFile: prdPath,
|
sourceFile: prdPath,
|
||||||
generatedAt: new Date().toISOString().split('T')[0]
|
generatedAt: new Date().toISOString().split('T')[0]
|
||||||
@@ -418,11 +485,24 @@ function processClaudeResponse(textContent, numTasks, retryCount, prdContent, pr
|
|||||||
|
|
||||||
// Try again with Claude for a cleaner response
|
// Try again with Claude for a cleaner response
|
||||||
if (retryCount === 1) {
|
if (retryCount === 1) {
|
||||||
report("Calling Claude again for a cleaner response...", 'info');
|
report('Calling Claude again for a cleaner response...', 'info');
|
||||||
return callClaude(prdContent, prdPath, numTasks, retryCount + 1, options);
|
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 {
|
} else {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
@@ -441,11 +521,22 @@ function processClaudeResponse(textContent, numTasks, retryCount, prdContent, pr
|
|||||||
* - session: Session object from MCP server (optional)
|
* - session: Session object from MCP server (optional)
|
||||||
* @returns {Array} Generated subtasks
|
* @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 {
|
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 streamingInterval = null;
|
||||||
let responseText = '';
|
let responseText = '';
|
||||||
|
|
||||||
@@ -468,8 +559,9 @@ For each subtask, provide:
|
|||||||
|
|
||||||
Each subtask should be implementable in a focused coding session.`;
|
Each subtask should be implementable in a focused coding session.`;
|
||||||
|
|
||||||
const contextPrompt = additionalContext ?
|
const contextPrompt = additionalContext
|
||||||
`\n\nAdditional context to consider: ${additionalContext}` : '';
|
? `\n\nAdditional context to consider: ${additionalContext}`
|
||||||
|
: '';
|
||||||
|
|
||||||
const userPrompt = `Please break down this task into ${numSubtasks} specific, actionable subtasks:
|
const userPrompt = `Please break down this task into ${numSubtasks} specific, actionable subtasks:
|
||||||
|
|
||||||
@@ -499,7 +591,9 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
|||||||
const readline = await import('readline');
|
const readline = await import('readline');
|
||||||
streamingInterval = setInterval(() => {
|
streamingInterval = setInterval(() => {
|
||||||
readline.cursorTo(process.stdout, 0);
|
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;
|
dotCount = (dotCount + 1) % 4;
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
@@ -526,10 +620,14 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
|||||||
responseText += chunk.delta.text;
|
responseText += chunk.delta.text;
|
||||||
}
|
}
|
||||||
if (reportProgress) {
|
if (reportProgress) {
|
||||||
await reportProgress({ progress: (responseText.length / CONFIG.maxTokens) * 100 });
|
await reportProgress({
|
||||||
|
progress: (responseText.length / CONFIG.maxTokens) * 100
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (mcpLog) {
|
if (mcpLog) {
|
||||||
mcpLog.info(`Progress: ${responseText.length / CONFIG.maxTokens * 100}%`);
|
mcpLog.info(
|
||||||
|
`Progress: ${(responseText.length / CONFIG.maxTokens) * 100}%`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -538,7 +636,12 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
|||||||
|
|
||||||
log('info', `Completed generating subtasks for task ${task.id}`);
|
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) {
|
} catch (error) {
|
||||||
if (streamingInterval) clearInterval(streamingInterval);
|
if (streamingInterval) clearInterval(streamingInterval);
|
||||||
stopLoadingIndicator(loadingIndicator);
|
stopLoadingIndicator(loadingIndicator);
|
||||||
@@ -563,26 +666,38 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
|||||||
* - session: Session object from MCP server (optional)
|
* - session: Session object from MCP server (optional)
|
||||||
* @returns {Array} Generated subtasks
|
* @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
|
// 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
|
// Use mcpLog if provided, otherwise use regular log if not silent
|
||||||
const logFn = mcpLog ?
|
const logFn = mcpLog
|
||||||
(level, ...args) => mcpLog[level](...args) :
|
? (level, ...args) => mcpLog[level](...args)
|
||||||
(level, ...args) => !isSilent && log(level, ...args);
|
: (level, ...args) => !isSilent && log(level, ...args);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// First, perform research to get context
|
// First, perform research to get context
|
||||||
logFn('info', `Researching context for task ${task.id}: ${task.title}`);
|
logFn('info', `Researching context for task ${task.id}: ${task.title}`);
|
||||||
const perplexityClient = getPerplexityClient();
|
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
|
// Only create loading indicators if not in silent mode
|
||||||
let researchLoadingIndicator = null;
|
let researchLoadingIndicator = null;
|
||||||
if (!isSilent) {
|
if (!isSilent) {
|
||||||
researchLoadingIndicator = startLoadingIndicator('Researching best practices with Perplexity AI...');
|
researchLoadingIndicator = startLoadingIndicator(
|
||||||
|
'Researching best practices with Perplexity AI...'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Formulate research query based on task
|
// Formulate research query based on task
|
||||||
@@ -593,10 +708,12 @@ Include concrete code examples and technical considerations where relevant.`;
|
|||||||
// Query Perplexity for research
|
// Query Perplexity for research
|
||||||
const researchResponse = await perplexityClient.chat.completions.create({
|
const researchResponse = await perplexityClient.chat.completions.create({
|
||||||
model: PERPLEXITY_MODEL,
|
model: PERPLEXITY_MODEL,
|
||||||
messages: [{
|
messages: [
|
||||||
|
{
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: researchQuery
|
content: researchQuery
|
||||||
}],
|
}
|
||||||
|
],
|
||||||
temperature: 0.1 // Lower temperature for more factual responses
|
temperature: 0.1 // Lower temperature for more factual responses
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -607,7 +724,10 @@ Include concrete code examples and technical considerations where relevant.`;
|
|||||||
stopLoadingIndicator(researchLoadingIndicator);
|
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
|
// Use the research result as additional context for Claude to generate subtasks
|
||||||
const combinedContext = `
|
const combinedContext = `
|
||||||
@@ -615,13 +735,15 @@ RESEARCH FINDINGS:
|
|||||||
${researchResult}
|
${researchResult}
|
||||||
|
|
||||||
ADDITIONAL CONTEXT PROVIDED BY USER:
|
ADDITIONAL CONTEXT PROVIDED BY USER:
|
||||||
${additionalContext || "No additional context provided."}
|
${additionalContext || 'No additional context provided.'}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// Now generate subtasks with Claude
|
// Now generate subtasks with Claude
|
||||||
let loadingIndicator = null;
|
let loadingIndicator = null;
|
||||||
if (!isSilent) {
|
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;
|
let streamingInterval = null;
|
||||||
@@ -680,7 +802,9 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
|||||||
const readline = await import('readline');
|
const readline = await import('readline');
|
||||||
streamingInterval = setInterval(() => {
|
streamingInterval = setInterval(() => {
|
||||||
readline.cursorTo(process.stdout, 0);
|
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;
|
dotCount = (dotCount + 1) % 4;
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
@@ -710,9 +834,17 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
|||||||
loadingIndicator = null;
|
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) {
|
} catch (error) {
|
||||||
// Clean up on error
|
// Clean up on error
|
||||||
if (streamingInterval) {
|
if (streamingInterval) {
|
||||||
@@ -726,7 +858,10 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logFn('error', `Error generating research-backed subtasks: ${error.message}`);
|
logFn(
|
||||||
|
'error',
|
||||||
|
`Error generating research-backed subtasks: ${error.message}`
|
||||||
|
);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -738,42 +873,68 @@ Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use
|
|||||||
* @param {number} expectedCount - Expected number of subtasks
|
* @param {number} expectedCount - Expected number of subtasks
|
||||||
* @param {number} parentTaskId - Parent task ID
|
* @param {number} parentTaskId - Parent task ID
|
||||||
* @returns {Array} Parsed subtasks
|
* @returns {Array} Parsed subtasks
|
||||||
|
* @throws {Error} If parsing fails or JSON is invalid
|
||||||
*/
|
*/
|
||||||
function parseSubtasksFromText(text, startId, expectedCount, parentTaskId) {
|
function parseSubtasksFromText(text, startId, expectedCount, parentTaskId) {
|
||||||
try {
|
// 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');
|
||||||
|
}
|
||||||
|
|
||||||
// Locate JSON array in the text
|
// Locate JSON array in the text
|
||||||
const jsonStartIndex = text.indexOf('[');
|
const jsonStartIndex = text.indexOf('[');
|
||||||
const jsonEndIndex = text.lastIndexOf(']');
|
const jsonEndIndex = text.lastIndexOf(']');
|
||||||
|
|
||||||
if (jsonStartIndex === -1 || jsonEndIndex === -1 || jsonEndIndex < jsonStartIndex) {
|
// If no valid JSON array found, throw error
|
||||||
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
|
// Extract and parse the JSON
|
||||||
const jsonText = text.substring(jsonStartIndex, jsonEndIndex + 1);
|
const jsonText = text.substring(jsonStartIndex, jsonEndIndex + 1);
|
||||||
let subtasks = JSON.parse(jsonText);
|
let subtasks;
|
||||||
|
|
||||||
// Validate
|
try {
|
||||||
|
subtasks = JSON.parse(jsonText);
|
||||||
|
} catch (parseError) {
|
||||||
|
throw new Error(`Failed to parse JSON: ${parseError.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate array
|
||||||
if (!Array.isArray(subtasks)) {
|
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
|
// Log warning if count doesn't match expected
|
||||||
if (subtasks.length !== expectedCount) {
|
if (expectedCount && subtasks.length !== expectedCount) {
|
||||||
log('warn', `Expected ${expectedCount} subtasks, but parsed ${subtasks.length}`);
|
log(
|
||||||
|
'warn',
|
||||||
|
`Expected ${expectedCount} subtasks, but parsed ${subtasks.length}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalize subtask IDs if they don't match
|
// Normalize subtask IDs if they don't match
|
||||||
subtasks = subtasks.map((subtask, index) => {
|
subtasks = subtasks.map((subtask, index) => {
|
||||||
// Assign the correct ID if it doesn't match
|
// Assign the correct ID if it doesn't match
|
||||||
if (subtask.id !== startId + index) {
|
if (!subtask.id || subtask.id !== startId + index) {
|
||||||
log('warn', `Correcting subtask ID from ${subtask.id} to ${startId + index}`);
|
log(
|
||||||
|
'warn',
|
||||||
|
`Correcting subtask ID from ${subtask.id || 'undefined'} to ${startId + index}`
|
||||||
|
);
|
||||||
subtask.id = startId + index;
|
subtask.id = startId + index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert dependencies to numbers if they are strings
|
// Convert dependencies to numbers if they are strings
|
||||||
if (subtask.dependencies && Array.isArray(subtask.dependencies)) {
|
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;
|
return typeof dep === 'string' ? parseInt(dep, 10) : dep;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -783,35 +944,15 @@ function parseSubtasksFromText(text, startId, expectedCount, parentTaskId) {
|
|||||||
// Ensure status is 'pending'
|
// Ensure status is 'pending'
|
||||||
subtask.status = 'pending';
|
subtask.status = 'pending';
|
||||||
|
|
||||||
// Add parentTaskId
|
// Add parentTaskId if provided
|
||||||
|
if (parentTaskId) {
|
||||||
subtask.parentTaskId = parentTaskId;
|
subtask.parentTaskId = parentTaskId;
|
||||||
|
}
|
||||||
|
|
||||||
return subtask;
|
return subtask;
|
||||||
});
|
});
|
||||||
|
|
||||||
return subtasks;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -822,14 +963,18 @@ function parseSubtasksFromText(text, startId, expectedCount, parentTaskId) {
|
|||||||
function generateComplexityAnalysisPrompt(tasksData) {
|
function generateComplexityAnalysisPrompt(tasksData) {
|
||||||
return `Analyze the complexity of the following tasks and provide recommendations for subtask breakdown:
|
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}
|
Task ID: ${task.id}
|
||||||
Title: ${task.title}
|
Title: ${task.title}
|
||||||
Description: ${task.description}
|
Description: ${task.description}
|
||||||
Details: ${task.details}
|
Details: ${task.details}
|
||||||
Dependencies: ${JSON.stringify(task.dependencies || [])}
|
Dependencies: ${JSON.stringify(task.dependencies || [])}
|
||||||
Priority: ${task.priority || 'medium'}
|
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:
|
Analyze each task and return a JSON array with the following structure for each task:
|
||||||
[
|
[
|
||||||
@@ -866,20 +1011,28 @@ 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
|
* @param {boolean} [cliMode=false] - Whether to show CLI-specific output like spinners
|
||||||
* @returns {Promise<string>} The accumulated response text
|
* @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
|
// Only set up loading indicator in CLI mode and not in silent mode
|
||||||
let loadingIndicator = null;
|
let loadingIndicator = null;
|
||||||
let streamingInterval = null;
|
let streamingInterval = null;
|
||||||
let responseText = '';
|
let responseText = '';
|
||||||
|
|
||||||
// Check both the passed parameter and global silent mode using isSilentMode()
|
// 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
|
// Only show CLI indicators if in cliMode AND not in silent mode
|
||||||
const showCLIOutput = cliMode && !isSilent;
|
const showCLIOutput = cliMode && !isSilent;
|
||||||
|
|
||||||
if (showCLIOutput) {
|
if (showCLIOutput) {
|
||||||
loadingIndicator = startLoadingIndicator('Processing request with Claude AI...');
|
loadingIndicator = startLoadingIndicator(
|
||||||
|
'Processing request with Claude AI...'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -888,7 +1041,11 @@ async function _handleAnthropicStream(client, params, { reportProgress, mcpLog,
|
|||||||
throw new Error('Anthropic client is required');
|
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');
|
throw new Error('At least one message is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -907,7 +1064,9 @@ async function _handleAnthropicStream(client, params, { reportProgress, mcpLog,
|
|||||||
const readline = await import('readline');
|
const readline = await import('readline');
|
||||||
streamingInterval = setInterval(() => {
|
streamingInterval = setInterval(() => {
|
||||||
readline.cursorTo(process.stdout, 0);
|
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;
|
dotCount = (dotCount + 1) % 4;
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
@@ -933,7 +1092,10 @@ async function _handleAnthropicStream(client, params, { reportProgress, mcpLog,
|
|||||||
|
|
||||||
// Report progress - use only mcpLog in MCP context and avoid direct reportProgress calls
|
// Report progress - use only mcpLog in MCP context and avoid direct reportProgress calls
|
||||||
const maxTokens = params.max_tokens || CONFIG.maxTokens;
|
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
|
// Only use reportProgress in CLI mode, not from MCP context, and not in silent mode
|
||||||
if (reportProgress && !mcpLog && !isSilent) {
|
if (reportProgress && !mcpLog && !isSilent) {
|
||||||
@@ -945,7 +1107,9 @@ async function _handleAnthropicStream(client, params, { reportProgress, mcpLog,
|
|||||||
|
|
||||||
// Log progress if logger is provided (MCP mode)
|
// Log progress if logger is provided (MCP mode)
|
||||||
if (mcpLog) {
|
if (mcpLog) {
|
||||||
mcpLog.info(`Progress: ${progressPercent}% (${responseText.length} chars generated)`);
|
mcpLog.info(
|
||||||
|
`Progress: ${progressPercent}% (${responseText.length} chars generated)`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (iterError) {
|
} catch (iterError) {
|
||||||
// Handle iteration errors
|
// Handle iteration errors
|
||||||
@@ -956,7 +1120,10 @@ async function _handleAnthropicStream(client, params, { reportProgress, mcpLog,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If it's a "stream finished" error, just break the loop
|
// 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;
|
streamDone = true;
|
||||||
} else {
|
} else {
|
||||||
// For other errors, rethrow
|
// For other errors, rethrow
|
||||||
@@ -978,9 +1145,9 @@ async function _handleAnthropicStream(client, params, { reportProgress, mcpLog,
|
|||||||
|
|
||||||
// Log completion
|
// Log completion
|
||||||
if (mcpLog) {
|
if (mcpLog) {
|
||||||
mcpLog.info("Completed streaming response from Claude API!");
|
mcpLog.info('Completed streaming response from Claude API!');
|
||||||
} else if (!isSilent) {
|
} else if (!isSilent) {
|
||||||
log('info', "Completed streaming response from Claude API!");
|
log('info', 'Completed streaming response from Claude API!');
|
||||||
}
|
}
|
||||||
|
|
||||||
return responseText;
|
return responseText;
|
||||||
@@ -1024,8 +1191,12 @@ function parseTaskJsonResponse(responseText) {
|
|||||||
const jsonStartIndex = jsonContent.indexOf('{');
|
const jsonStartIndex = jsonContent.indexOf('{');
|
||||||
const jsonEndIndex = jsonContent.lastIndexOf('}');
|
const jsonEndIndex = jsonContent.lastIndexOf('}');
|
||||||
|
|
||||||
if (jsonStartIndex === -1 || jsonEndIndex === -1 || jsonEndIndex < jsonStartIndex) {
|
if (
|
||||||
throw new Error("Could not locate valid JSON object in the response");
|
jsonStartIndex === -1 ||
|
||||||
|
jsonEndIndex === -1 ||
|
||||||
|
jsonEndIndex < jsonStartIndex
|
||||||
|
) {
|
||||||
|
throw new Error('Could not locate valid JSON object in the response');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract and parse the JSON
|
// Extract and parse the JSON
|
||||||
@@ -1034,13 +1205,17 @@ function parseTaskJsonResponse(responseText) {
|
|||||||
|
|
||||||
// Validate required fields
|
// Validate required fields
|
||||||
if (!taskData.title || !taskData.description) {
|
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;
|
return taskData;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.name === 'SyntaxError') {
|
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;
|
throw error;
|
||||||
}
|
}
|
||||||
@@ -1056,7 +1231,8 @@ function parseTaskJsonResponse(responseText) {
|
|||||||
*/
|
*/
|
||||||
function _buildAddTaskPrompt(prompt, contextTasks, { newTaskId } = {}) {
|
function _buildAddTaskPrompt(prompt, contextTasks, { newTaskId } = {}) {
|
||||||
// Create the system prompt for Claude
|
// 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 = `
|
const taskStructure = `
|
||||||
{
|
{
|
||||||
@@ -1094,10 +1270,13 @@ function getAnthropicClient(session) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize a new client with API key from session or environment
|
// 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) {
|
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({
|
return new Anthropic({
|
||||||
@@ -1118,14 +1297,22 @@ function getAnthropicClient(session) {
|
|||||||
* @param {Object} options.session - Session object from MCP server
|
* @param {Object} options.session - Session object from MCP server
|
||||||
* @returns {Object} - The generated task description
|
* @returns {Object} - The generated task description
|
||||||
*/
|
*/
|
||||||
async function generateTaskDescriptionWithPerplexity(prompt, { reportProgress, mcpLog, session } = {}) {
|
async function generateTaskDescriptionWithPerplexity(
|
||||||
|
prompt,
|
||||||
|
{ reportProgress, mcpLog, session } = {}
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
// First, perform research to get context
|
// First, perform research to get context
|
||||||
log('info', `Researching context for task prompt: "${prompt}"`);
|
log('info', `Researching context for task prompt: "${prompt}"`);
|
||||||
const perplexityClient = getPerplexityClient();
|
const perplexityClient = getPerplexityClient();
|
||||||
|
|
||||||
const PERPLEXITY_MODEL = process.env.PERPLEXITY_MODEL || session?.env?.PERPLEXITY_MODEL || 'sonar-pro';
|
const PERPLEXITY_MODEL =
|
||||||
const researchLoadingIndicator = startLoadingIndicator('Researching best practices with Perplexity AI...');
|
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
|
// Formulate research query based on task prompt
|
||||||
const researchQuery = `I need to implement: "${prompt}".
|
const researchQuery = `I need to implement: "${prompt}".
|
||||||
@@ -1135,10 +1322,12 @@ Include concrete code examples and technical considerations where relevant.`;
|
|||||||
// Query Perplexity for research
|
// Query Perplexity for research
|
||||||
const researchResponse = await perplexityClient.chat.completions.create({
|
const researchResponse = await perplexityClient.chat.completions.create({
|
||||||
model: PERPLEXITY_MODEL,
|
model: PERPLEXITY_MODEL,
|
||||||
messages: [{
|
messages: [
|
||||||
|
{
|
||||||
role: 'user',
|
role: 'user',
|
||||||
content: researchQuery
|
content: researchQuery
|
||||||
}],
|
}
|
||||||
|
],
|
||||||
temperature: 0.1 // Lower temperature for more factual responses
|
temperature: 0.1 // Lower temperature for more factual responses
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1148,7 +1337,9 @@ Include concrete code examples and technical considerations where relevant.`;
|
|||||||
log('info', 'Research completed, now generating detailed task description');
|
log('info', 'Research completed, now generating detailed task description');
|
||||||
|
|
||||||
// Now generate task description with Claude
|
// 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 streamingInterval = null;
|
||||||
let responseText = '';
|
let responseText = '';
|
||||||
|
|
||||||
@@ -1185,7 +1376,9 @@ Return a JSON object with the following structure:
|
|||||||
const readline = await import('readline');
|
const readline = await import('readline');
|
||||||
streamingInterval = setInterval(() => {
|
streamingInterval = setInterval(() => {
|
||||||
readline.cursorTo(process.stdout, 0);
|
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;
|
dotCount = (dotCount + 1) % 4;
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
@@ -1210,10 +1403,14 @@ Return a JSON object with the following structure:
|
|||||||
responseText += chunk.delta.text;
|
responseText += chunk.delta.text;
|
||||||
}
|
}
|
||||||
if (reportProgress) {
|
if (reportProgress) {
|
||||||
await reportProgress({ progress: (responseText.length / CONFIG.maxTokens) * 100 });
|
await reportProgress({
|
||||||
|
progress: (responseText.length / CONFIG.maxTokens) * 100
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (mcpLog) {
|
if (mcpLog) {
|
||||||
mcpLog.info(`Progress: ${responseText.length / CONFIG.maxTokens * 100}%`);
|
mcpLog.info(
|
||||||
|
`Progress: ${(responseText.length / CONFIG.maxTokens) * 100}%`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1229,7 +1426,10 @@ Return a JSON object with the following structure:
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
} catch (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;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1242,10 +1442,15 @@ Return a JSON object with the following structure:
|
|||||||
*/
|
*/
|
||||||
function getConfiguredAnthropicClient(session = null, customEnv = null) {
|
function getConfiguredAnthropicClient(session = null, customEnv = null) {
|
||||||
// If we have a session with ANTHROPIC_API_KEY in env, use that
|
// 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) {
|
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({
|
return new Anthropic({
|
||||||
@@ -1264,9 +1469,18 @@ function getConfiguredAnthropicClient(session = null, customEnv = null) {
|
|||||||
* @param {Object} options - Options containing reportProgress, mcpLog, silentMode, and session
|
* @param {Object} options - Options containing reportProgress, mcpLog, silentMode, and session
|
||||||
* @returns {string} - Response text
|
* @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
|
// 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
@@ -23,10 +23,9 @@ import { generateTaskFiles } from './task-manager.js';
|
|||||||
|
|
||||||
// Initialize Anthropic client
|
// Initialize Anthropic client
|
||||||
const anthropic = new Anthropic({
|
const anthropic = new Anthropic({
|
||||||
apiKey: process.env.ANTHROPIC_API_KEY,
|
apiKey: process.env.ANTHROPIC_API_KEY
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a dependency to a task
|
* Add a dependency to a task
|
||||||
* @param {string} tasksPath - Path to the tasks.json file
|
* @param {string} tasksPath - Path to the tasks.json file
|
||||||
@@ -43,14 +42,19 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Format the task and dependency IDs correctly
|
// Format the task and dependency IDs correctly
|
||||||
const formattedTaskId = typeof taskId === 'string' && taskId.includes('.')
|
const formattedTaskId =
|
||||||
? taskId : parseInt(taskId, 10);
|
typeof taskId === 'string' && taskId.includes('.')
|
||||||
|
? taskId
|
||||||
|
: parseInt(taskId, 10);
|
||||||
|
|
||||||
const formattedDependencyId = formatTaskId(dependencyId);
|
const formattedDependencyId = formatTaskId(dependencyId);
|
||||||
|
|
||||||
// Check if the dependency task or subtask actually exists
|
// Check if the dependency task or subtask actually exists
|
||||||
if (!taskExists(data.tasks, formattedDependencyId)) {
|
if (!taskExists(data.tasks, formattedDependencyId)) {
|
||||||
log('error', `Dependency target ${formattedDependencyId} does not exist in tasks.json`);
|
log(
|
||||||
|
'error',
|
||||||
|
`Dependency target ${formattedDependencyId} does not exist in tasks.json`
|
||||||
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,8 +64,10 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
if (typeof formattedTaskId === 'string' && formattedTaskId.includes('.')) {
|
if (typeof formattedTaskId === 'string' && formattedTaskId.includes('.')) {
|
||||||
// Handle dot notation for subtasks (e.g., "1.2")
|
// Handle dot notation for subtasks (e.g., "1.2")
|
||||||
const [parentId, subtaskId] = formattedTaskId.split('.').map(id => parseInt(id, 10));
|
const [parentId, subtaskId] = formattedTaskId
|
||||||
const parentTask = data.tasks.find(t => t.id === parentId);
|
.split('.')
|
||||||
|
.map((id) => parseInt(id, 10));
|
||||||
|
const parentTask = data.tasks.find((t) => t.id === parentId);
|
||||||
|
|
||||||
if (!parentTask) {
|
if (!parentTask) {
|
||||||
log('error', `Parent task ${parentId} not found.`);
|
log('error', `Parent task ${parentId} not found.`);
|
||||||
@@ -73,7 +79,7 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
targetTask = parentTask.subtasks.find(s => s.id === subtaskId);
|
targetTask = parentTask.subtasks.find((s) => s.id === subtaskId);
|
||||||
isSubtask = true;
|
isSubtask = true;
|
||||||
|
|
||||||
if (!targetTask) {
|
if (!targetTask) {
|
||||||
@@ -82,7 +88,7 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Regular task (not a subtask)
|
// Regular task (not a subtask)
|
||||||
targetTask = data.tasks.find(t => t.id === formattedTaskId);
|
targetTask = data.tasks.find((t) => t.id === formattedTaskId);
|
||||||
|
|
||||||
if (!targetTask) {
|
if (!targetTask) {
|
||||||
log('error', `Task ${formattedTaskId} not found.`);
|
log('error', `Task ${formattedTaskId} not found.`);
|
||||||
@@ -96,11 +102,16 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if dependency already exists
|
// Check if dependency already exists
|
||||||
if (targetTask.dependencies.some(d => {
|
if (
|
||||||
|
targetTask.dependencies.some((d) => {
|
||||||
// Convert both to strings for comparison to handle both numeric and string IDs
|
// Convert both to strings for comparison to handle both numeric and string IDs
|
||||||
return String(d) === String(formattedDependencyId);
|
return String(d) === String(formattedDependencyId);
|
||||||
})) {
|
})
|
||||||
log('warn', `Dependency ${formattedDependencyId} already exists in task ${formattedTaskId}.`);
|
) {
|
||||||
|
log(
|
||||||
|
'warn',
|
||||||
|
`Dependency ${formattedDependencyId} already exists in task ${formattedTaskId}.`
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,8 +125,12 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
// Check if we're dealing with subtasks with the same parent task
|
// Check if we're dealing with subtasks with the same parent task
|
||||||
let isSelfDependency = false;
|
let isSelfDependency = false;
|
||||||
|
|
||||||
if (typeof formattedTaskId === 'string' && typeof formattedDependencyId === 'string' &&
|
if (
|
||||||
formattedTaskId.includes('.') && formattedDependencyId.includes('.')) {
|
typeof formattedTaskId === 'string' &&
|
||||||
|
typeof formattedDependencyId === 'string' &&
|
||||||
|
formattedTaskId.includes('.') &&
|
||||||
|
formattedDependencyId.includes('.')
|
||||||
|
) {
|
||||||
const [taskParentId] = formattedTaskId.split('.');
|
const [taskParentId] = formattedTaskId.split('.');
|
||||||
const [depParentId] = formattedDependencyId.split('.');
|
const [depParentId] = formattedDependencyId.split('.');
|
||||||
|
|
||||||
@@ -123,8 +138,14 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
isSelfDependency = formattedTaskId === formattedDependencyId;
|
isSelfDependency = formattedTaskId === formattedDependencyId;
|
||||||
|
|
||||||
// Log for debugging
|
// Log for debugging
|
||||||
log('debug', `Adding dependency between subtasks: ${formattedTaskId} depends on ${formattedDependencyId}`);
|
log(
|
||||||
log('debug', `Parent IDs: ${taskParentId} and ${depParentId}, Self-dependency check: ${isSelfDependency}`);
|
'debug',
|
||||||
|
`Adding dependency between subtasks: ${formattedTaskId} depends on ${formattedDependencyId}`
|
||||||
|
);
|
||||||
|
log(
|
||||||
|
'debug',
|
||||||
|
`Parent IDs: ${taskParentId} and ${depParentId}, Self-dependency check: ${isSelfDependency}`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSelfDependency) {
|
if (isSelfDependency) {
|
||||||
@@ -134,7 +155,9 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
// Check for circular dependencies
|
// Check for circular dependencies
|
||||||
let dependencyChain = [formattedTaskId];
|
let dependencyChain = [formattedTaskId];
|
||||||
if (!isCircularDependency(data.tasks, formattedDependencyId, dependencyChain)) {
|
if (
|
||||||
|
!isCircularDependency(data.tasks, formattedDependencyId, dependencyChain)
|
||||||
|
) {
|
||||||
// Add the dependency
|
// Add the dependency
|
||||||
targetTask.dependencies.push(formattedDependencyId);
|
targetTask.dependencies.push(formattedDependencyId);
|
||||||
|
|
||||||
@@ -155,21 +178,34 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
// Save changes
|
// Save changes
|
||||||
writeJSON(tasksPath, data);
|
writeJSON(tasksPath, data);
|
||||||
log('success', `Added dependency ${formattedDependencyId} to task ${formattedTaskId}`);
|
log(
|
||||||
|
'success',
|
||||||
|
`Added dependency ${formattedDependencyId} to task ${formattedTaskId}`
|
||||||
|
);
|
||||||
|
|
||||||
// Display a more visually appealing success message
|
// Display a more visually appealing success message
|
||||||
console.log(boxen(
|
console.log(
|
||||||
|
boxen(
|
||||||
chalk.green(`Successfully added dependency:\n\n`) +
|
chalk.green(`Successfully added dependency:\n\n`) +
|
||||||
`Task ${chalk.bold(formattedTaskId)} now depends on ${chalk.bold(formattedDependencyId)}`,
|
`Task ${chalk.bold(formattedTaskId)} now depends on ${chalk.bold(formattedDependencyId)}`,
|
||||||
{ padding: 1, borderColor: 'green', borderStyle: 'round', margin: { top: 1 } }
|
{
|
||||||
));
|
padding: 1,
|
||||||
|
borderColor: 'green',
|
||||||
|
borderStyle: 'round',
|
||||||
|
margin: { top: 1 }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// Generate updated task files
|
// Generate updated task files
|
||||||
await generateTaskFiles(tasksPath, 'tasks');
|
await generateTaskFiles(tasksPath, 'tasks');
|
||||||
|
|
||||||
log('info', 'Task files regenerated with updated dependencies.');
|
log('info', 'Task files regenerated with updated dependencies.');
|
||||||
} else {
|
} else {
|
||||||
log('error', `Cannot add dependency ${formattedDependencyId} to task ${formattedTaskId} as it would create a circular dependency.`);
|
log(
|
||||||
|
'error',
|
||||||
|
`Cannot add dependency ${formattedDependencyId} to task ${formattedTaskId} as it would create a circular dependency.`
|
||||||
|
);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,13 +222,15 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
// Read tasks file
|
// Read tasks file
|
||||||
const data = readJSON(tasksPath);
|
const data = readJSON(tasksPath);
|
||||||
if (!data || !data.tasks) {
|
if (!data || !data.tasks) {
|
||||||
log('error', "No valid tasks found.");
|
log('error', 'No valid tasks found.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format the task and dependency IDs correctly
|
// Format the task and dependency IDs correctly
|
||||||
const formattedTaskId = typeof taskId === 'string' && taskId.includes('.')
|
const formattedTaskId =
|
||||||
? taskId : parseInt(taskId, 10);
|
typeof taskId === 'string' && taskId.includes('.')
|
||||||
|
? taskId
|
||||||
|
: parseInt(taskId, 10);
|
||||||
|
|
||||||
const formattedDependencyId = formatTaskId(dependencyId);
|
const formattedDependencyId = formatTaskId(dependencyId);
|
||||||
|
|
||||||
@@ -202,8 +240,10 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
if (typeof formattedTaskId === 'string' && formattedTaskId.includes('.')) {
|
if (typeof formattedTaskId === 'string' && formattedTaskId.includes('.')) {
|
||||||
// Handle dot notation for subtasks (e.g., "1.2")
|
// Handle dot notation for subtasks (e.g., "1.2")
|
||||||
const [parentId, subtaskId] = formattedTaskId.split('.').map(id => parseInt(id, 10));
|
const [parentId, subtaskId] = formattedTaskId
|
||||||
const parentTask = data.tasks.find(t => t.id === parentId);
|
.split('.')
|
||||||
|
.map((id) => parseInt(id, 10));
|
||||||
|
const parentTask = data.tasks.find((t) => t.id === parentId);
|
||||||
|
|
||||||
if (!parentTask) {
|
if (!parentTask) {
|
||||||
log('error', `Parent task ${parentId} not found.`);
|
log('error', `Parent task ${parentId} not found.`);
|
||||||
@@ -215,7 +255,7 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
targetTask = parentTask.subtasks.find(s => s.id === subtaskId);
|
targetTask = parentTask.subtasks.find((s) => s.id === subtaskId);
|
||||||
isSubtask = true;
|
isSubtask = true;
|
||||||
|
|
||||||
if (!targetTask) {
|
if (!targetTask) {
|
||||||
@@ -224,7 +264,7 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Regular task (not a subtask)
|
// Regular task (not a subtask)
|
||||||
targetTask = data.tasks.find(t => t.id === formattedTaskId);
|
targetTask = data.tasks.find((t) => t.id === formattedTaskId);
|
||||||
|
|
||||||
if (!targetTask) {
|
if (!targetTask) {
|
||||||
log('error', `Task ${formattedTaskId} not found.`);
|
log('error', `Task ${formattedTaskId} not found.`);
|
||||||
@@ -234,7 +274,10 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
// Check if the task has any dependencies
|
// Check if the task has any dependencies
|
||||||
if (!targetTask.dependencies || targetTask.dependencies.length === 0) {
|
if (!targetTask.dependencies || targetTask.dependencies.length === 0) {
|
||||||
log('info', `Task ${formattedTaskId} has no dependencies, nothing to remove.`);
|
log(
|
||||||
|
'info',
|
||||||
|
`Task ${formattedTaskId} has no dependencies, nothing to remove.`
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +285,7 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
const normalizedDependencyId = String(formattedDependencyId);
|
const normalizedDependencyId = String(formattedDependencyId);
|
||||||
|
|
||||||
// Check if the dependency exists by comparing string representations
|
// Check if the dependency exists by comparing string representations
|
||||||
const dependencyIndex = targetTask.dependencies.findIndex(dep => {
|
const dependencyIndex = targetTask.dependencies.findIndex((dep) => {
|
||||||
// Convert both to strings for comparison
|
// Convert both to strings for comparison
|
||||||
let depStr = String(dep);
|
let depStr = String(dep);
|
||||||
|
|
||||||
@@ -258,7 +301,10 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (dependencyIndex === -1) {
|
if (dependencyIndex === -1) {
|
||||||
log('info', `Task ${formattedTaskId} does not depend on ${formattedDependencyId}, no changes made.`);
|
log(
|
||||||
|
'info',
|
||||||
|
`Task ${formattedTaskId} does not depend on ${formattedDependencyId}, no changes made.`
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,14 +315,24 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
writeJSON(tasksPath, data);
|
writeJSON(tasksPath, data);
|
||||||
|
|
||||||
// Success message
|
// Success message
|
||||||
log('success', `Removed dependency: Task ${formattedTaskId} no longer depends on ${formattedDependencyId}`);
|
log(
|
||||||
|
'success',
|
||||||
|
`Removed dependency: Task ${formattedTaskId} no longer depends on ${formattedDependencyId}`
|
||||||
|
);
|
||||||
|
|
||||||
// Display a more visually appealing success message
|
// Display a more visually appealing success message
|
||||||
console.log(boxen(
|
console.log(
|
||||||
|
boxen(
|
||||||
chalk.green(`Successfully removed dependency:\n\n`) +
|
chalk.green(`Successfully removed dependency:\n\n`) +
|
||||||
`Task ${chalk.bold(formattedTaskId)} no longer depends on ${chalk.bold(formattedDependencyId)}`,
|
`Task ${chalk.bold(formattedTaskId)} no longer depends on ${chalk.bold(formattedDependencyId)}`,
|
||||||
{ padding: 1, borderColor: 'green', borderStyle: 'round', margin: { top: 1 } }
|
{
|
||||||
));
|
padding: 1,
|
||||||
|
borderColor: 'green',
|
||||||
|
borderStyle: 'round',
|
||||||
|
margin: { top: 1 }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// Regenerate task files
|
// Regenerate task files
|
||||||
await generateTaskFiles(tasksPath, 'tasks');
|
await generateTaskFiles(tasksPath, 'tasks');
|
||||||
@@ -294,7 +350,7 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
const taskIdStr = String(taskId);
|
const taskIdStr = String(taskId);
|
||||||
|
|
||||||
// If we've seen this task before in the chain, we have a circular dependency
|
// If we've seen this task before in the chain, we have a circular dependency
|
||||||
if (chain.some(id => String(id) === taskIdStr)) {
|
if (chain.some((id) => String(id) === taskIdStr)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,14 +360,14 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
// Check if this is a subtask reference (e.g., "1.2")
|
// Check if this is a subtask reference (e.g., "1.2")
|
||||||
if (taskIdStr.includes('.')) {
|
if (taskIdStr.includes('.')) {
|
||||||
const [parentId, subtaskId] = taskIdStr.split('.').map(Number);
|
const [parentId, subtaskId] = taskIdStr.split('.').map(Number);
|
||||||
const parentTask = tasks.find(t => t.id === parentId);
|
const parentTask = tasks.find((t) => t.id === parentId);
|
||||||
|
|
||||||
if (parentTask && parentTask.subtasks) {
|
if (parentTask && parentTask.subtasks) {
|
||||||
task = parentTask.subtasks.find(st => st.id === subtaskId);
|
task = parentTask.subtasks.find((st) => st.id === subtaskId);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Regular task
|
// Regular task
|
||||||
task = tasks.find(t => String(t.id) === taskIdStr);
|
task = tasks.find((t) => String(t.id) === taskIdStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!task) {
|
if (!task) {
|
||||||
@@ -325,7 +381,9 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
// Check each dependency recursively
|
// Check each dependency recursively
|
||||||
const newChain = [...chain, taskId];
|
const newChain = [...chain, taskId];
|
||||||
return task.dependencies.some(depId => isCircularDependency(tasks, depId, newChain));
|
return task.dependencies.some((depId) =>
|
||||||
|
isCircularDependency(tasks, depId, newChain)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -337,12 +395,12 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
const issues = [];
|
const issues = [];
|
||||||
|
|
||||||
// Check each task's dependencies
|
// Check each task's dependencies
|
||||||
tasks.forEach(task => {
|
tasks.forEach((task) => {
|
||||||
if (!task.dependencies) {
|
if (!task.dependencies) {
|
||||||
return; // No dependencies to validate
|
return; // No dependencies to validate
|
||||||
}
|
}
|
||||||
|
|
||||||
task.dependencies.forEach(depId => {
|
task.dependencies.forEach((depId) => {
|
||||||
// Check for self-dependencies
|
// Check for self-dependencies
|
||||||
if (String(depId) === String(task.id)) {
|
if (String(depId) === String(task.id)) {
|
||||||
issues.push({
|
issues.push({
|
||||||
@@ -375,7 +433,7 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
// Check subtask dependencies if they exist
|
// Check subtask dependencies if they exist
|
||||||
if (task.subtasks && task.subtasks.length > 0) {
|
if (task.subtasks && task.subtasks.length > 0) {
|
||||||
task.subtasks.forEach(subtask => {
|
task.subtasks.forEach((subtask) => {
|
||||||
if (!subtask.dependencies) {
|
if (!subtask.dependencies) {
|
||||||
return; // No dependencies to validate
|
return; // No dependencies to validate
|
||||||
}
|
}
|
||||||
@@ -383,10 +441,12 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
// Create a full subtask ID for reference
|
// Create a full subtask ID for reference
|
||||||
const fullSubtaskId = `${task.id}.${subtask.id}`;
|
const fullSubtaskId = `${task.id}.${subtask.id}`;
|
||||||
|
|
||||||
subtask.dependencies.forEach(depId => {
|
subtask.dependencies.forEach((depId) => {
|
||||||
// Check for self-dependencies in subtasks
|
// Check for self-dependencies in subtasks
|
||||||
if (String(depId) === String(fullSubtaskId) ||
|
if (
|
||||||
(typeof depId === 'number' && depId === subtask.id)) {
|
String(depId) === String(fullSubtaskId) ||
|
||||||
|
(typeof depId === 'number' && depId === subtask.id)
|
||||||
|
) {
|
||||||
issues.push({
|
issues.push({
|
||||||
type: 'self',
|
type: 'self',
|
||||||
taskId: fullSubtaskId,
|
taskId: fullSubtaskId,
|
||||||
@@ -430,7 +490,7 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
* @returns {Object} Updated tasks data with duplicates removed
|
* @returns {Object} Updated tasks data with duplicates removed
|
||||||
*/
|
*/
|
||||||
function removeDuplicateDependencies(tasksData) {
|
function removeDuplicateDependencies(tasksData) {
|
||||||
const tasks = tasksData.tasks.map(task => {
|
const tasks = tasksData.tasks.map((task) => {
|
||||||
if (!task.dependencies) {
|
if (!task.dependencies) {
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
@@ -455,10 +515,10 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
* @returns {Object} Updated tasks data with invalid subtask dependencies removed
|
* @returns {Object} Updated tasks data with invalid subtask dependencies removed
|
||||||
*/
|
*/
|
||||||
function cleanupSubtaskDependencies(tasksData) {
|
function cleanupSubtaskDependencies(tasksData) {
|
||||||
const tasks = tasksData.tasks.map(task => {
|
const tasks = tasksData.tasks.map((task) => {
|
||||||
// Handle task's own dependencies
|
// Handle task's own dependencies
|
||||||
if (task.dependencies) {
|
if (task.dependencies) {
|
||||||
task.dependencies = task.dependencies.filter(depId => {
|
task.dependencies = task.dependencies.filter((depId) => {
|
||||||
// Keep only dependencies that exist
|
// Keep only dependencies that exist
|
||||||
return taskExists(tasksData.tasks, depId);
|
return taskExists(tasksData.tasks, depId);
|
||||||
});
|
});
|
||||||
@@ -466,13 +526,13 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
// Handle subtask dependencies
|
// Handle subtask dependencies
|
||||||
if (task.subtasks) {
|
if (task.subtasks) {
|
||||||
task.subtasks = task.subtasks.map(subtask => {
|
task.subtasks = task.subtasks.map((subtask) => {
|
||||||
if (!subtask.dependencies) {
|
if (!subtask.dependencies) {
|
||||||
return subtask;
|
return subtask;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter out dependencies to non-existent subtasks
|
// Filter out dependencies to non-existent subtasks
|
||||||
subtask.dependencies = subtask.dependencies.filter(depId => {
|
subtask.dependencies = subtask.dependencies.filter((depId) => {
|
||||||
return taskExists(tasksData.tasks, depId);
|
return taskExists(tasksData.tasks, depId);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -508,13 +568,16 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
// Count of tasks and subtasks for reporting
|
// Count of tasks and subtasks for reporting
|
||||||
const taskCount = data.tasks.length;
|
const taskCount = data.tasks.length;
|
||||||
let subtaskCount = 0;
|
let subtaskCount = 0;
|
||||||
data.tasks.forEach(task => {
|
data.tasks.forEach((task) => {
|
||||||
if (task.subtasks && Array.isArray(task.subtasks)) {
|
if (task.subtasks && Array.isArray(task.subtasks)) {
|
||||||
subtaskCount += task.subtasks.length;
|
subtaskCount += task.subtasks.length;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
log('info', `Analyzing dependencies for ${taskCount} tasks and ${subtaskCount} subtasks...`);
|
log(
|
||||||
|
'info',
|
||||||
|
`Analyzing dependencies for ${taskCount} tasks and ${subtaskCount} subtasks...`
|
||||||
|
);
|
||||||
|
|
||||||
// Track validation statistics
|
// Track validation statistics
|
||||||
const stats = {
|
const stats = {
|
||||||
@@ -566,22 +629,39 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
const result = (() => {
|
const result = (() => {
|
||||||
// Use Function.prototype.bind to create a new function that has logProxy available
|
// Use Function.prototype.bind to create a new function that has logProxy available
|
||||||
// Pass isCircularDependency explicitly to make it available
|
// Pass isCircularDependency explicitly to make it available
|
||||||
return Function('tasks', 'tasksPath', 'log', 'customLogger', 'isCircularDependency', 'taskExists',
|
return Function(
|
||||||
|
'tasks',
|
||||||
|
'tasksPath',
|
||||||
|
'log',
|
||||||
|
'customLogger',
|
||||||
|
'isCircularDependency',
|
||||||
|
'taskExists',
|
||||||
`return (${originalValidateTaskDependencies.toString()})(tasks, tasksPath);`
|
`return (${originalValidateTaskDependencies.toString()})(tasks, tasksPath);`
|
||||||
)(tasks, tasksPath, logProxy, customLogger, isCircularDependency, taskExists);
|
)(
|
||||||
|
tasks,
|
||||||
|
tasksPath,
|
||||||
|
logProxy,
|
||||||
|
customLogger,
|
||||||
|
isCircularDependency,
|
||||||
|
taskExists
|
||||||
|
);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const changesDetected = patchedValidateTaskDependencies(data.tasks, tasksPath);
|
const changesDetected = patchedValidateTaskDependencies(
|
||||||
|
data.tasks,
|
||||||
|
tasksPath
|
||||||
|
);
|
||||||
|
|
||||||
// Create a detailed report
|
// Create a detailed report
|
||||||
if (changesDetected) {
|
if (changesDetected) {
|
||||||
log('success', 'Invalid dependencies were removed from tasks.json');
|
log('success', 'Invalid dependencies were removed from tasks.json');
|
||||||
|
|
||||||
// Show detailed stats in a nice box
|
// Show detailed stats in a nice box
|
||||||
console.log(boxen(
|
console.log(
|
||||||
|
boxen(
|
||||||
chalk.green(`Dependency Validation Results:\n\n`) +
|
chalk.green(`Dependency Validation Results:\n\n`) +
|
||||||
`${chalk.cyan('Tasks checked:')} ${taskCount}\n` +
|
`${chalk.cyan('Tasks checked:')} ${taskCount}\n` +
|
||||||
`${chalk.cyan('Subtasks checked:')} ${subtaskCount}\n` +
|
`${chalk.cyan('Subtasks checked:')} ${subtaskCount}\n` +
|
||||||
@@ -589,13 +669,19 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
`${chalk.cyan('Self-dependencies removed:')} ${stats.selfDependenciesRemoved}\n` +
|
`${chalk.cyan('Self-dependencies removed:')} ${stats.selfDependenciesRemoved}\n` +
|
||||||
`${chalk.cyan('Tasks fixed:')} ${stats.tasksFixed}\n` +
|
`${chalk.cyan('Tasks fixed:')} ${stats.tasksFixed}\n` +
|
||||||
`${chalk.cyan('Subtasks fixed:')} ${stats.subtasksFixed}`,
|
`${chalk.cyan('Subtasks fixed:')} ${stats.subtasksFixed}`,
|
||||||
{ padding: 1, borderColor: 'green', borderStyle: 'round', margin: { top: 1, bottom: 1 } }
|
{
|
||||||
));
|
padding: 1,
|
||||||
|
borderColor: 'green',
|
||||||
|
borderStyle: 'round',
|
||||||
|
margin: { top: 1, bottom: 1 }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// Show all warnings in a collapsible list if there are many
|
// Show all warnings in a collapsible list if there are many
|
||||||
if (warnings.length > 0) {
|
if (warnings.length > 0) {
|
||||||
console.log(chalk.yellow('\nDetailed fixes:'));
|
console.log(chalk.yellow('\nDetailed fixes:'));
|
||||||
warnings.forEach(warning => {
|
warnings.forEach((warning) => {
|
||||||
console.log(` ${warning}`);
|
console.log(` ${warning}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -604,16 +690,26 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
await generateTaskFiles(tasksPath, path.dirname(tasksPath));
|
await generateTaskFiles(tasksPath, path.dirname(tasksPath));
|
||||||
log('info', 'Task files regenerated to reflect dependency changes');
|
log('info', 'Task files regenerated to reflect dependency changes');
|
||||||
} else {
|
} else {
|
||||||
log('success', 'No invalid dependencies found - all dependencies are valid');
|
log(
|
||||||
|
'success',
|
||||||
|
'No invalid dependencies found - all dependencies are valid'
|
||||||
|
);
|
||||||
|
|
||||||
// Show validation summary
|
// Show validation summary
|
||||||
console.log(boxen(
|
console.log(
|
||||||
|
boxen(
|
||||||
chalk.green(`All Dependencies Are Valid\n\n`) +
|
chalk.green(`All Dependencies Are Valid\n\n`) +
|
||||||
`${chalk.cyan('Tasks checked:')} ${taskCount}\n` +
|
`${chalk.cyan('Tasks checked:')} ${taskCount}\n` +
|
||||||
`${chalk.cyan('Subtasks checked:')} ${subtaskCount}\n` +
|
`${chalk.cyan('Subtasks checked:')} ${subtaskCount}\n` +
|
||||||
`${chalk.cyan('Total dependencies verified:')} ${countAllDependencies(data.tasks)}`,
|
`${chalk.cyan('Total dependencies verified:')} ${countAllDependencies(data.tasks)}`,
|
||||||
{ padding: 1, borderColor: 'green', borderStyle: 'round', margin: { top: 1, bottom: 1 } }
|
{
|
||||||
));
|
padding: 1,
|
||||||
|
borderColor: 'green',
|
||||||
|
borderStyle: 'round',
|
||||||
|
margin: { top: 1, bottom: 1 }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log('error', 'Error validating dependencies:', error);
|
log('error', 'Error validating dependencies:', error);
|
||||||
@@ -629,7 +725,7 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
function countAllDependencies(tasks) {
|
function countAllDependencies(tasks) {
|
||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
||||||
tasks.forEach(task => {
|
tasks.forEach((task) => {
|
||||||
// Count main task dependencies
|
// Count main task dependencies
|
||||||
if (task.dependencies && Array.isArray(task.dependencies)) {
|
if (task.dependencies && Array.isArray(task.dependencies)) {
|
||||||
count += task.dependencies.length;
|
count += task.dependencies.length;
|
||||||
@@ -637,7 +733,7 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
// Count subtask dependencies
|
// Count subtask dependencies
|
||||||
if (task.subtasks && Array.isArray(task.subtasks)) {
|
if (task.subtasks && Array.isArray(task.subtasks)) {
|
||||||
task.subtasks.forEach(subtask => {
|
task.subtasks.forEach((subtask) => {
|
||||||
if (subtask.dependencies && Array.isArray(subtask.dependencies)) {
|
if (subtask.dependencies && Array.isArray(subtask.dependencies)) {
|
||||||
count += subtask.dependencies.length;
|
count += subtask.dependencies.length;
|
||||||
}
|
}
|
||||||
@@ -679,14 +775,17 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// First phase: Remove duplicate dependencies in tasks
|
// First phase: Remove duplicate dependencies in tasks
|
||||||
data.tasks.forEach(task => {
|
data.tasks.forEach((task) => {
|
||||||
if (task.dependencies && Array.isArray(task.dependencies)) {
|
if (task.dependencies && Array.isArray(task.dependencies)) {
|
||||||
const uniqueDeps = new Set();
|
const uniqueDeps = new Set();
|
||||||
const originalLength = task.dependencies.length;
|
const originalLength = task.dependencies.length;
|
||||||
task.dependencies = task.dependencies.filter(depId => {
|
task.dependencies = task.dependencies.filter((depId) => {
|
||||||
const depIdStr = String(depId);
|
const depIdStr = String(depId);
|
||||||
if (uniqueDeps.has(depIdStr)) {
|
if (uniqueDeps.has(depIdStr)) {
|
||||||
log('info', `Removing duplicate dependency from task ${task.id}: ${depId}`);
|
log(
|
||||||
|
'info',
|
||||||
|
`Removing duplicate dependency from task ${task.id}: ${depId}`
|
||||||
|
);
|
||||||
stats.duplicateDependenciesRemoved++;
|
stats.duplicateDependenciesRemoved++;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -700,17 +799,20 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
// Check for duplicates in subtasks
|
// Check for duplicates in subtasks
|
||||||
if (task.subtasks && Array.isArray(task.subtasks)) {
|
if (task.subtasks && Array.isArray(task.subtasks)) {
|
||||||
task.subtasks.forEach(subtask => {
|
task.subtasks.forEach((subtask) => {
|
||||||
if (subtask.dependencies && Array.isArray(subtask.dependencies)) {
|
if (subtask.dependencies && Array.isArray(subtask.dependencies)) {
|
||||||
const uniqueDeps = new Set();
|
const uniqueDeps = new Set();
|
||||||
const originalLength = subtask.dependencies.length;
|
const originalLength = subtask.dependencies.length;
|
||||||
subtask.dependencies = subtask.dependencies.filter(depId => {
|
subtask.dependencies = subtask.dependencies.filter((depId) => {
|
||||||
let depIdStr = String(depId);
|
let depIdStr = String(depId);
|
||||||
if (typeof depId === 'number' && depId < 100) {
|
if (typeof depId === 'number' && depId < 100) {
|
||||||
depIdStr = `${task.id}.${depId}`;
|
depIdStr = `${task.id}.${depId}`;
|
||||||
}
|
}
|
||||||
if (uniqueDeps.has(depIdStr)) {
|
if (uniqueDeps.has(depIdStr)) {
|
||||||
log('info', `Removing duplicate dependency from subtask ${task.id}.${subtask.id}: ${depId}`);
|
log(
|
||||||
|
'info',
|
||||||
|
`Removing duplicate dependency from subtask ${task.id}.${subtask.id}: ${depId}`
|
||||||
|
);
|
||||||
stats.duplicateDependenciesRemoved++;
|
stats.duplicateDependenciesRemoved++;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -726,36 +828,43 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Create validity maps for tasks and subtasks
|
// Create validity maps for tasks and subtasks
|
||||||
const validTaskIds = new Set(data.tasks.map(t => t.id));
|
const validTaskIds = new Set(data.tasks.map((t) => t.id));
|
||||||
const validSubtaskIds = new Set();
|
const validSubtaskIds = new Set();
|
||||||
data.tasks.forEach(task => {
|
data.tasks.forEach((task) => {
|
||||||
if (task.subtasks && Array.isArray(task.subtasks)) {
|
if (task.subtasks && Array.isArray(task.subtasks)) {
|
||||||
task.subtasks.forEach(subtask => {
|
task.subtasks.forEach((subtask) => {
|
||||||
validSubtaskIds.add(`${task.id}.${subtask.id}`);
|
validSubtaskIds.add(`${task.id}.${subtask.id}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Second phase: Remove invalid task dependencies (non-existent tasks)
|
// Second phase: Remove invalid task dependencies (non-existent tasks)
|
||||||
data.tasks.forEach(task => {
|
data.tasks.forEach((task) => {
|
||||||
if (task.dependencies && Array.isArray(task.dependencies)) {
|
if (task.dependencies && Array.isArray(task.dependencies)) {
|
||||||
const originalLength = task.dependencies.length;
|
const originalLength = task.dependencies.length;
|
||||||
task.dependencies = task.dependencies.filter(depId => {
|
task.dependencies = task.dependencies.filter((depId) => {
|
||||||
const isSubtask = typeof depId === 'string' && depId.includes('.');
|
const isSubtask = typeof depId === 'string' && depId.includes('.');
|
||||||
|
|
||||||
if (isSubtask) {
|
if (isSubtask) {
|
||||||
// Check if the subtask exists
|
// Check if the subtask exists
|
||||||
if (!validSubtaskIds.has(depId)) {
|
if (!validSubtaskIds.has(depId)) {
|
||||||
log('info', `Removing invalid subtask dependency from task ${task.id}: ${depId} (subtask does not exist)`);
|
log(
|
||||||
|
'info',
|
||||||
|
`Removing invalid subtask dependency from task ${task.id}: ${depId} (subtask does not exist)`
|
||||||
|
);
|
||||||
stats.nonExistentDependenciesRemoved++;
|
stats.nonExistentDependenciesRemoved++;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// Check if the task exists
|
// Check if the task exists
|
||||||
const numericId = typeof depId === 'string' ? parseInt(depId, 10) : depId;
|
const numericId =
|
||||||
|
typeof depId === 'string' ? parseInt(depId, 10) : depId;
|
||||||
if (!validTaskIds.has(numericId)) {
|
if (!validTaskIds.has(numericId)) {
|
||||||
log('info', `Removing invalid task dependency from task ${task.id}: ${depId} (task does not exist)`);
|
log(
|
||||||
|
'info',
|
||||||
|
`Removing invalid task dependency from task ${task.id}: ${depId} (task does not exist)`
|
||||||
|
);
|
||||||
stats.nonExistentDependenciesRemoved++;
|
stats.nonExistentDependenciesRemoved++;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -770,13 +879,13 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
// Check subtask dependencies for invalid references
|
// Check subtask dependencies for invalid references
|
||||||
if (task.subtasks && Array.isArray(task.subtasks)) {
|
if (task.subtasks && Array.isArray(task.subtasks)) {
|
||||||
task.subtasks.forEach(subtask => {
|
task.subtasks.forEach((subtask) => {
|
||||||
if (subtask.dependencies && Array.isArray(subtask.dependencies)) {
|
if (subtask.dependencies && Array.isArray(subtask.dependencies)) {
|
||||||
const originalLength = subtask.dependencies.length;
|
const originalLength = subtask.dependencies.length;
|
||||||
const subtaskId = `${task.id}.${subtask.id}`;
|
const subtaskId = `${task.id}.${subtask.id}`;
|
||||||
|
|
||||||
// First check for self-dependencies
|
// First check for self-dependencies
|
||||||
const hasSelfDependency = subtask.dependencies.some(depId => {
|
const hasSelfDependency = subtask.dependencies.some((depId) => {
|
||||||
if (typeof depId === 'string' && depId.includes('.')) {
|
if (typeof depId === 'string' && depId.includes('.')) {
|
||||||
return depId === subtaskId;
|
return depId === subtaskId;
|
||||||
} else if (typeof depId === 'number' && depId < 100) {
|
} else if (typeof depId === 'number' && depId < 100) {
|
||||||
@@ -786,13 +895,17 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (hasSelfDependency) {
|
if (hasSelfDependency) {
|
||||||
subtask.dependencies = subtask.dependencies.filter(depId => {
|
subtask.dependencies = subtask.dependencies.filter((depId) => {
|
||||||
const normalizedDepId = typeof depId === 'number' && depId < 100
|
const normalizedDepId =
|
||||||
|
typeof depId === 'number' && depId < 100
|
||||||
? `${task.id}.${depId}`
|
? `${task.id}.${depId}`
|
||||||
: String(depId);
|
: String(depId);
|
||||||
|
|
||||||
if (normalizedDepId === subtaskId) {
|
if (normalizedDepId === subtaskId) {
|
||||||
log('info', `Removing self-dependency from subtask ${subtaskId}`);
|
log(
|
||||||
|
'info',
|
||||||
|
`Removing self-dependency from subtask ${subtaskId}`
|
||||||
|
);
|
||||||
stats.selfDependenciesRemoved++;
|
stats.selfDependenciesRemoved++;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -801,10 +914,13 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Then check for non-existent dependencies
|
// Then check for non-existent dependencies
|
||||||
subtask.dependencies = subtask.dependencies.filter(depId => {
|
subtask.dependencies = subtask.dependencies.filter((depId) => {
|
||||||
if (typeof depId === 'string' && depId.includes('.')) {
|
if (typeof depId === 'string' && depId.includes('.')) {
|
||||||
if (!validSubtaskIds.has(depId)) {
|
if (!validSubtaskIds.has(depId)) {
|
||||||
log('info', `Removing invalid subtask dependency from subtask ${subtaskId}: ${depId} (subtask does not exist)`);
|
log(
|
||||||
|
'info',
|
||||||
|
`Removing invalid subtask dependency from subtask ${subtaskId}: ${depId} (subtask does not exist)`
|
||||||
|
);
|
||||||
stats.nonExistentDependenciesRemoved++;
|
stats.nonExistentDependenciesRemoved++;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -812,14 +928,18 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle numeric dependencies
|
// Handle numeric dependencies
|
||||||
const numericId = typeof depId === 'number' ? depId : parseInt(depId, 10);
|
const numericId =
|
||||||
|
typeof depId === 'number' ? depId : parseInt(depId, 10);
|
||||||
|
|
||||||
// Small numbers likely refer to subtasks in the same task
|
// Small numbers likely refer to subtasks in the same task
|
||||||
if (numericId < 100) {
|
if (numericId < 100) {
|
||||||
const fullSubtaskId = `${task.id}.${numericId}`;
|
const fullSubtaskId = `${task.id}.${numericId}`;
|
||||||
|
|
||||||
if (!validSubtaskIds.has(fullSubtaskId)) {
|
if (!validSubtaskIds.has(fullSubtaskId)) {
|
||||||
log('info', `Removing invalid subtask dependency from subtask ${subtaskId}: ${numericId}`);
|
log(
|
||||||
|
'info',
|
||||||
|
`Removing invalid subtask dependency from subtask ${subtaskId}: ${numericId}`
|
||||||
|
);
|
||||||
stats.nonExistentDependenciesRemoved++;
|
stats.nonExistentDependenciesRemoved++;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -829,7 +949,10 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
// Otherwise it's a task reference
|
// Otherwise it's a task reference
|
||||||
if (!validTaskIds.has(numericId)) {
|
if (!validTaskIds.has(numericId)) {
|
||||||
log('info', `Removing invalid task dependency from subtask ${subtaskId}: ${numericId}`);
|
log(
|
||||||
|
'info',
|
||||||
|
`Removing invalid task dependency from subtask ${subtaskId}: ${numericId}`
|
||||||
|
);
|
||||||
stats.nonExistentDependenciesRemoved++;
|
stats.nonExistentDependenciesRemoved++;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -850,13 +973,13 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
// Build the dependency map for subtasks
|
// Build the dependency map for subtasks
|
||||||
const subtaskDependencyMap = new Map();
|
const subtaskDependencyMap = new Map();
|
||||||
data.tasks.forEach(task => {
|
data.tasks.forEach((task) => {
|
||||||
if (task.subtasks && Array.isArray(task.subtasks)) {
|
if (task.subtasks && Array.isArray(task.subtasks)) {
|
||||||
task.subtasks.forEach(subtask => {
|
task.subtasks.forEach((subtask) => {
|
||||||
const subtaskId = `${task.id}.${subtask.id}`;
|
const subtaskId = `${task.id}.${subtask.id}`;
|
||||||
|
|
||||||
if (subtask.dependencies && Array.isArray(subtask.dependencies)) {
|
if (subtask.dependencies && Array.isArray(subtask.dependencies)) {
|
||||||
const normalizedDeps = subtask.dependencies.map(depId => {
|
const normalizedDeps = subtask.dependencies.map((depId) => {
|
||||||
if (typeof depId === 'string' && depId.includes('.')) {
|
if (typeof depId === 'string' && depId.includes('.')) {
|
||||||
return depId;
|
return depId;
|
||||||
} else if (typeof depId === 'number' && depId < 100) {
|
} else if (typeof depId === 'number' && depId < 100) {
|
||||||
@@ -878,21 +1001,30 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
const recursionStack = new Set();
|
const recursionStack = new Set();
|
||||||
|
|
||||||
// Detect cycles
|
// Detect cycles
|
||||||
const cycleEdges = findCycles(subtaskId, subtaskDependencyMap, visited, recursionStack);
|
const cycleEdges = findCycles(
|
||||||
|
subtaskId,
|
||||||
|
subtaskDependencyMap,
|
||||||
|
visited,
|
||||||
|
recursionStack
|
||||||
|
);
|
||||||
|
|
||||||
if (cycleEdges.length > 0) {
|
if (cycleEdges.length > 0) {
|
||||||
const [taskId, subtaskNum] = subtaskId.split('.').map(part => Number(part));
|
const [taskId, subtaskNum] = subtaskId
|
||||||
const task = data.tasks.find(t => t.id === taskId);
|
.split('.')
|
||||||
|
.map((part) => Number(part));
|
||||||
|
const task = data.tasks.find((t) => t.id === taskId);
|
||||||
|
|
||||||
if (task && task.subtasks) {
|
if (task && task.subtasks) {
|
||||||
const subtask = task.subtasks.find(st => st.id === subtaskNum);
|
const subtask = task.subtasks.find((st) => st.id === subtaskNum);
|
||||||
|
|
||||||
if (subtask && subtask.dependencies) {
|
if (subtask && subtask.dependencies) {
|
||||||
const originalLength = subtask.dependencies.length;
|
const originalLength = subtask.dependencies.length;
|
||||||
|
|
||||||
const edgesToRemove = cycleEdges.map(edge => {
|
const edgesToRemove = cycleEdges.map((edge) => {
|
||||||
if (edge.includes('.')) {
|
if (edge.includes('.')) {
|
||||||
const [depTaskId, depSubtaskId] = edge.split('.').map(part => Number(part));
|
const [depTaskId, depSubtaskId] = edge
|
||||||
|
.split('.')
|
||||||
|
.map((part) => Number(part));
|
||||||
|
|
||||||
if (depTaskId === taskId) {
|
if (depTaskId === taskId) {
|
||||||
return depSubtaskId;
|
return depSubtaskId;
|
||||||
@@ -904,13 +1036,20 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
return Number(edge);
|
return Number(edge);
|
||||||
});
|
});
|
||||||
|
|
||||||
subtask.dependencies = subtask.dependencies.filter(depId => {
|
subtask.dependencies = subtask.dependencies.filter((depId) => {
|
||||||
const normalizedDepId = typeof depId === 'number' && depId < 100
|
const normalizedDepId =
|
||||||
|
typeof depId === 'number' && depId < 100
|
||||||
? `${taskId}.${depId}`
|
? `${taskId}.${depId}`
|
||||||
: String(depId);
|
: String(depId);
|
||||||
|
|
||||||
if (edgesToRemove.includes(depId) || edgesToRemove.includes(normalizedDepId)) {
|
if (
|
||||||
log('info', `Breaking circular dependency: Removing ${normalizedDepId} from subtask ${subtaskId}`);
|
edgesToRemove.includes(depId) ||
|
||||||
|
edgesToRemove.includes(normalizedDepId)
|
||||||
|
) {
|
||||||
|
log(
|
||||||
|
'info',
|
||||||
|
`Breaking circular dependency: Removing ${normalizedDepId} from subtask ${subtaskId}`
|
||||||
|
);
|
||||||
stats.circularDependenciesFixed++;
|
stats.circularDependenciesFixed++;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -941,7 +1080,8 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Show detailed statistics report
|
// Show detailed statistics report
|
||||||
const totalFixedAll = stats.nonExistentDependenciesRemoved +
|
const totalFixedAll =
|
||||||
|
stats.nonExistentDependenciesRemoved +
|
||||||
stats.selfDependenciesRemoved +
|
stats.selfDependenciesRemoved +
|
||||||
stats.duplicateDependenciesRemoved +
|
stats.duplicateDependenciesRemoved +
|
||||||
stats.circularDependenciesFixed;
|
stats.circularDependenciesFixed;
|
||||||
@@ -949,7 +1089,8 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
if (totalFixedAll > 0) {
|
if (totalFixedAll > 0) {
|
||||||
log('success', `Fixed ${totalFixedAll} dependency issues in total!`);
|
log('success', `Fixed ${totalFixedAll} dependency issues in total!`);
|
||||||
|
|
||||||
console.log(boxen(
|
console.log(
|
||||||
|
boxen(
|
||||||
chalk.green(`Dependency Fixes Summary:\n\n`) +
|
chalk.green(`Dependency Fixes Summary:\n\n`) +
|
||||||
`${chalk.cyan('Invalid dependencies removed:')} ${stats.nonExistentDependenciesRemoved}\n` +
|
`${chalk.cyan('Invalid dependencies removed:')} ${stats.nonExistentDependenciesRemoved}\n` +
|
||||||
`${chalk.cyan('Self-dependencies removed:')} ${stats.selfDependenciesRemoved}\n` +
|
`${chalk.cyan('Self-dependencies removed:')} ${stats.selfDependenciesRemoved}\n` +
|
||||||
@@ -957,20 +1098,33 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
`${chalk.cyan('Circular dependencies fixed:')} ${stats.circularDependenciesFixed}\n\n` +
|
`${chalk.cyan('Circular dependencies fixed:')} ${stats.circularDependenciesFixed}\n\n` +
|
||||||
`${chalk.cyan('Tasks fixed:')} ${stats.tasksFixed}\n` +
|
`${chalk.cyan('Tasks fixed:')} ${stats.tasksFixed}\n` +
|
||||||
`${chalk.cyan('Subtasks fixed:')} ${stats.subtasksFixed}\n`,
|
`${chalk.cyan('Subtasks fixed:')} ${stats.subtasksFixed}\n`,
|
||||||
{ padding: 1, borderColor: 'green', borderStyle: 'round', margin: { top: 1, bottom: 1 } }
|
{
|
||||||
));
|
padding: 1,
|
||||||
|
borderColor: 'green',
|
||||||
|
borderStyle: 'round',
|
||||||
|
margin: { top: 1, bottom: 1 }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
log('success', 'No dependency issues found - all dependencies are valid');
|
log('success', 'No dependency issues found - all dependencies are valid');
|
||||||
|
|
||||||
console.log(boxen(
|
console.log(
|
||||||
|
boxen(
|
||||||
chalk.green(`All Dependencies Are Valid\n\n`) +
|
chalk.green(`All Dependencies Are Valid\n\n`) +
|
||||||
`${chalk.cyan('Tasks checked:')} ${data.tasks.length}\n` +
|
`${chalk.cyan('Tasks checked:')} ${data.tasks.length}\n` +
|
||||||
`${chalk.cyan('Total dependencies verified:')} ${countAllDependencies(data.tasks)}`,
|
`${chalk.cyan('Total dependencies verified:')} ${countAllDependencies(data.tasks)}`,
|
||||||
{ padding: 1, borderColor: 'green', borderStyle: 'round', margin: { top: 1, bottom: 1 } }
|
{
|
||||||
));
|
padding: 1,
|
||||||
|
borderColor: 'green',
|
||||||
|
borderStyle: 'round',
|
||||||
|
margin: { top: 1, bottom: 1 }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
log('error', "Error in fix-dependencies command:", error);
|
log('error', 'Error in fix-dependencies command:', error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -987,21 +1141,31 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
let changesDetected = false;
|
let changesDetected = false;
|
||||||
|
|
||||||
tasksData.tasks.forEach(task => {
|
tasksData.tasks.forEach((task) => {
|
||||||
if (!task.subtasks || !Array.isArray(task.subtasks) || task.subtasks.length === 0) {
|
if (
|
||||||
|
!task.subtasks ||
|
||||||
|
!Array.isArray(task.subtasks) ||
|
||||||
|
task.subtasks.length === 0
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if any subtask has no dependencies
|
// Check if any subtask has no dependencies
|
||||||
const hasIndependentSubtask = task.subtasks.some(st =>
|
const hasIndependentSubtask = task.subtasks.some(
|
||||||
!st.dependencies || !Array.isArray(st.dependencies) || st.dependencies.length === 0
|
(st) =>
|
||||||
|
!st.dependencies ||
|
||||||
|
!Array.isArray(st.dependencies) ||
|
||||||
|
st.dependencies.length === 0
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!hasIndependentSubtask) {
|
if (!hasIndependentSubtask) {
|
||||||
// Find the first subtask and clear its dependencies
|
// Find the first subtask and clear its dependencies
|
||||||
if (task.subtasks.length > 0) {
|
if (task.subtasks.length > 0) {
|
||||||
const firstSubtask = task.subtasks[0];
|
const firstSubtask = task.subtasks[0];
|
||||||
log('debug', `Ensuring at least one independent subtask: Clearing dependencies for subtask ${task.id}.${firstSubtask.id}`);
|
log(
|
||||||
|
'debug',
|
||||||
|
`Ensuring at least one independent subtask: Clearing dependencies for subtask ${task.id}.${firstSubtask.id}`
|
||||||
|
);
|
||||||
firstSubtask.dependencies = [];
|
firstSubtask.dependencies = [];
|
||||||
changesDetected = true;
|
changesDetected = true;
|
||||||
}
|
}
|
||||||
@@ -1030,7 +1194,7 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
const originalData = JSON.parse(JSON.stringify(tasksData));
|
const originalData = JSON.parse(JSON.stringify(tasksData));
|
||||||
|
|
||||||
// 1. Remove duplicate dependencies from tasks and subtasks
|
// 1. Remove duplicate dependencies from tasks and subtasks
|
||||||
tasksData.tasks = tasksData.tasks.map(task => {
|
tasksData.tasks = tasksData.tasks.map((task) => {
|
||||||
// Handle task dependencies
|
// Handle task dependencies
|
||||||
if (task.dependencies) {
|
if (task.dependencies) {
|
||||||
const uniqueDeps = [...new Set(task.dependencies)];
|
const uniqueDeps = [...new Set(task.dependencies)];
|
||||||
@@ -1039,7 +1203,7 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
// Handle subtask dependencies
|
// Handle subtask dependencies
|
||||||
if (task.subtasks) {
|
if (task.subtasks) {
|
||||||
task.subtasks = task.subtasks.map(subtask => {
|
task.subtasks = task.subtasks.map((subtask) => {
|
||||||
if (subtask.dependencies) {
|
if (subtask.dependencies) {
|
||||||
const uniqueDeps = [...new Set(subtask.dependencies)];
|
const uniqueDeps = [...new Set(subtask.dependencies)];
|
||||||
subtask.dependencies = uniqueDeps;
|
subtask.dependencies = uniqueDeps;
|
||||||
@@ -1051,10 +1215,10 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 2. Remove invalid task dependencies (non-existent tasks)
|
// 2. Remove invalid task dependencies (non-existent tasks)
|
||||||
tasksData.tasks.forEach(task => {
|
tasksData.tasks.forEach((task) => {
|
||||||
// Clean up task dependencies
|
// Clean up task dependencies
|
||||||
if (task.dependencies) {
|
if (task.dependencies) {
|
||||||
task.dependencies = task.dependencies.filter(depId => {
|
task.dependencies = task.dependencies.filter((depId) => {
|
||||||
// Remove self-dependencies
|
// Remove self-dependencies
|
||||||
if (String(depId) === String(task.id)) {
|
if (String(depId) === String(task.id)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -1066,9 +1230,9 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
|
|
||||||
// Clean up subtask dependencies
|
// Clean up subtask dependencies
|
||||||
if (task.subtasks) {
|
if (task.subtasks) {
|
||||||
task.subtasks.forEach(subtask => {
|
task.subtasks.forEach((subtask) => {
|
||||||
if (subtask.dependencies) {
|
if (subtask.dependencies) {
|
||||||
subtask.dependencies = subtask.dependencies.filter(depId => {
|
subtask.dependencies = subtask.dependencies.filter((depId) => {
|
||||||
// Handle numeric subtask references
|
// Handle numeric subtask references
|
||||||
if (typeof depId === 'number' && depId < 100) {
|
if (typeof depId === 'number' && depId < 100) {
|
||||||
const fullSubtaskId = `${task.id}.${depId}`;
|
const fullSubtaskId = `${task.id}.${depId}`;
|
||||||
@@ -1083,10 +1247,13 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 3. Ensure at least one subtask has no dependencies in each task
|
// 3. Ensure at least one subtask has no dependencies in each task
|
||||||
tasksData.tasks.forEach(task => {
|
tasksData.tasks.forEach((task) => {
|
||||||
if (task.subtasks && task.subtasks.length > 0) {
|
if (task.subtasks && task.subtasks.length > 0) {
|
||||||
const hasIndependentSubtask = task.subtasks.some(st =>
|
const hasIndependentSubtask = task.subtasks.some(
|
||||||
!st.dependencies || !Array.isArray(st.dependencies) || st.dependencies.length === 0
|
(st) =>
|
||||||
|
!st.dependencies ||
|
||||||
|
!Array.isArray(st.dependencies) ||
|
||||||
|
st.dependencies.length === 0
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!hasIndependentSubtask) {
|
if (!hasIndependentSubtask) {
|
||||||
@@ -1096,7 +1263,8 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Check if any changes were made by comparing with original data
|
// Check if any changes were made by comparing with original data
|
||||||
const changesDetected = JSON.stringify(tasksData) !== JSON.stringify(originalData);
|
const changesDetected =
|
||||||
|
JSON.stringify(tasksData) !== JSON.stringify(originalData);
|
||||||
|
|
||||||
// Save changes if needed
|
// Save changes if needed
|
||||||
if (tasksPath && changesDetected) {
|
if (tasksPath && changesDetected) {
|
||||||
@@ -1122,4 +1290,4 @@ async function addDependency(tasksPath, taskId, dependencyId) {
|
|||||||
cleanupSubtaskDependencies,
|
cleanupSubtaskDependencies,
|
||||||
ensureAtLeastOneIndependentSubtask,
|
ensureAtLeastOneIndependentSubtask,
|
||||||
validateAndFixDependencies
|
validateAndFixDependencies
|
||||||
}
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user