refactor(expand): Align expand-task with unified AI service

Refactored the `expandTask` feature (`scripts/modules/task-manager/expand-task.js`) and related components (`commands.js`, `mcp-server/src/tools/expand-task.js`, `mcp-server/src/core/direct-functions/expand-task.js`) to integrate with the unified AI service layer (`ai-services-unified.js`) and configuration management (`config-manager.js`).

The refactor involved:

- Removing direct AI client calls and configuration fetching from `expand-task.js`.

- Attempting to use `generateObjectService` for structured subtask generation. This failed due to provider-specific errors (Perplexity internal errors, Anthropic schema translation issues).

- Reverting the core AI interaction to use `generateTextService`, asking the LLM to format its response as JSON containing a "subtasks" array.

- Re-implementing manual JSON parsing and Zod validation (`parseSubtasksFromText`) to handle the text response reliably.

- Updating prompt generation functions (`generateMainSystemPrompt`, `generateMainUserPrompt`, `generateResearchUserPrompt`) to request the correct JSON object structure within the text response.

- Ensuring the `expandTaskDirect` function handles pre-checks (force flag, task status) and correctly passes the `session` context and logger wrapper to the core `expandTask` function.

- Correcting duplicate imports in `commands.js`.

- Validating the refactored feature works correctly via both CLI (`task-master expand --id <id>`) and MCP (`expand_task` tool) for main and research roles.

This aligns the task expansion feature with the new architecture while using the more robust text generation approach due to current limitations with structured output services. Closes subtask 61.37.
This commit is contained in:
Eyal Toledano
2025-04-25 01:26:42 -04:00
parent 70cc15bc87
commit 99b1a0ad7a
11 changed files with 1741 additions and 342 deletions

View File

@@ -723,7 +723,7 @@ async function generateSubtasksWithPerplexity(
// Formulate research query based on task
const researchQuery = `I need to implement "${task.title}" which involves: "${task.description}".
What are current best practices, libraries, design patterns, and implementation approaches?
Include concrete code examples and technical considerations where relevant.`;
Include concrete, researched, code examples and technical considerations where relevant. Include high-level, mid-level and low-level implementation details for a complete implementation.`;
// Query Perplexity for research
const researchResponse = await perplexityClient.chat.completions.create({
@@ -731,9 +731,9 @@ Include concrete code examples and technical considerations where relevant.`;
messages: [
{
role: 'system',
content: `You are a helpful assistant that provides research on current best practices and implementation approaches for software development.
You are given a task and a description of the task.
You need to provide a list of best practices, libraries, design patterns, and implementation approaches that are relevant to the task.
content: `You are an expert software development assistant and researcher that provides high level, mid level and low level research on current best practices and implementation approaches for software development.
You are given a task and a description of the task.
You need to provide a list of best practices, libraries, design patterns, and implementation approaches that are relevant to the task and up to date with today's latest best practices using those tools, libraries, design patterns and implementation approaches you are recommending.
You should provide concrete code examples and technical considerations where relevant.`
},
{