refactor(tasks): Align update-tasks with unified AI service and remove obsolete helpers

Completes the refactoring of the AI-interacting task management functions by aligning `update-tasks.js` with the unified service architecture and removing now-unused helper files.

Key Changes:

- **`update-tasks.js` Refactoring:**

    - Replaced direct AI client calls and AI-specific config fetching with a call to `generateTextService` from `ai-services-unified.js`.

    - Preserved the original system and user prompts requesting a JSON array output.

    - Implemented manual JSON parsing (`parseUpdatedTasksFromText`) with Zod validation to handle the text response reliably.

    - Updated the core function signature to accept the standard `context` object (`{ session, mcpLog }`).

    - Corrected logger implementation to handle both MCP (`mcpLog`) and CLI (`consoleLog`) contexts appropriately.

- **Related Component Updates:**

    - Refactored `mcp-server/src/core/direct-functions/update-tasks.js` to use the standard direct function pattern (logger wrapper, silent mode, call core function with context).

    - Verified `mcp-server/src/tools/update.js` correctly passes arguments and context.

    - Verified `scripts/modules/commands.js` (update command) correctly calls the refactored core function.

- **Obsolete File Cleanup:**

    - Removed the now-unused `scripts/modules/task-manager/get-subtasks-from-ai.js` file and its export, as its functionality was integrated into `expand-task.js`.

    - Removed the now-unused `scripts/modules/task-manager/generate-subtask-prompt.js` file and its export for the same reason.

- **Task Management:**

    - Marked subtasks 61.38, 61.39, and 61.41 as complete.

This commit finalizes the alignment of `updateTasks`, `updateTaskById`, `expandTask`, `expandAllTasks`, `analyzeTaskComplexity`, `addTask`, and `parsePRD` with the unified AI service and configuration management patterns.
This commit is contained in:
Eyal Toledano
2025-04-25 04:09:14 -04:00
parent ef782ff5bd
commit 3721359782
12 changed files with 676 additions and 804 deletions

View File

@@ -1957,7 +1957,7 @@ for (const task of pendingTasks) {
- Add or update JSDoc comments to clarify that this module is now a pure orchestrator and does not perform AI or config operations directly.
</info added on 2025-04-24T17:48:09.354Z>
## 39. Refactor get-subtasks-from-ai.js for Unified AI Service & Config [pending]
## 39. Refactor get-subtasks-from-ai.js for Unified AI Service & Config [done]
### Dependencies: None
### Description: Replace direct AI calls (old `ai-services.js` helpers) with `generateObjectService` or `generateTextService` from `ai-services-unified.js`. Pass `role` and `session`. Remove direct config getter usage (from `config-manager.js`) for AI parameters; use unified service instead.
### Details:
@@ -2043,7 +2043,7 @@ for (const task of pendingTasks) {
These enhancements ensure the refactored file is robust, maintainable, and aligned with the unified AI service architecture, leveraging Zod for strict runtime validation and clear error boundaries[5][1][3].
</info added on 2025-04-24T17:48:35.005Z>
## 40. Refactor update-task-by-id.js for Unified AI Service & Config [pending]
## 40. Refactor update-task-by-id.js for Unified AI Service & Config [done]
### Dependencies: None
### Description: Replace direct AI calls (old `ai-services.js` helpers) with `generateObjectService` or `generateTextService` from `ai-services-unified.js`. Pass `role` and `session`. Remove direct config getter usage (from `config-manager.js`) for AI parameters and fallback logic; use unified service instead. Keep `getDebugFlag`.
### Details:
@@ -2063,7 +2063,7 @@ These enhancements ensure the refactored file is robust, maintainable, and align
- If you need to validate or transform nested objects (such as task metadata or options), use Zod's object and nested schema capabilities to define these structures precisely, catching errors early and simplifying downstream logic[3][5].
</info added on 2025-04-24T17:48:58.133Z>
## 41. Refactor update-tasks.js for Unified AI Service & Config [pending]
## 41. Refactor update-tasks.js for Unified AI Service & Config [done]
### Dependencies: None
### Description: Replace direct AI calls (old `ai-services.js` helpers) with `generateObjectService` or `generateTextService` from `ai-services-unified.js`. Pass `role` and `session`. Remove direct config getter usage (from `config-manager.js`) for AI parameters and fallback logic; use unified service instead. Keep `getDebugFlag`.
### Details:
@@ -2149,3 +2149,15 @@ These enhancements ensure the refactored file is robust, maintainable, and align
These enhancements ensure robust validation, unified service usage, and maintainable, predictable batch update behavior.
</info added on 2025-04-24T17:49:25.126Z>
## 42. Remove all unused imports [pending]
### Dependencies: None
### Description:
### Details:
## 43. Remove all unnecessary console logs [pending]
### Dependencies: None
### Description:
### Details: