claude-task-master/scripts/modules/task-manager/generate-subtask-prompt.js
Eyal Toledano d46547a80f refactor(config): Standardize env var access and config getters
This commit focuses on standardizing configuration and API key access patterns across key modules as part of subtask 61.34.

Key changes include:

- Refactored `ai-services.js` to remove global AI clients and use `resolveEnvVariable` for API key checks. Client instantiation now relies on `getAnthropicClient`/`getPerplexityClient` accepting a session object.

- Refactored `task-manager.js` (`analyzeTaskComplexity` function) to use the unified `generateTextService` from `ai-services-unified.js`, removing direct AI client calls.

- Replaced direct `process.env` access for model parameters and other configurations (`PERPLEXITY_MODEL`, `CONFIG.*`) in `task-manager.js` with calls to the appropriate getters from `config-manager.js` (e.g., `getResearchModelId(session)`, `getMainMaxTokens(session)`).

- Ensured `utils.js` (`resolveEnvVariable`) correctly handles potentially undefined session objects.

- Updated function signatures where necessary to propagate the `session` object for correct context-aware configuration/key retrieval.

This moves towards the goal of using `ai-client-factory.js` and `ai-services-unified.js` as the standard pattern for AI interactions and centralizing configuration management through `config-manager.js`.
2025-04-21 17:48:30 -04:00

52 lines
1.9 KiB
JavaScript

/**
* Generate a prompt for creating subtasks from a task
* @param {Object} task - The task to generate subtasks for
* @param {number} numSubtasks - Number of subtasks to generate
* @param {string} additionalContext - Additional context to include in the prompt
* @param {Object} taskAnalysis - Optional complexity analysis for the task
* @returns {string} - The generated prompt
*/
function generateSubtaskPrompt(
task,
numSubtasks,
additionalContext = '',
taskAnalysis = null
) {
// Build the system prompt
const basePrompt = `You need to break down the following task into ${numSubtasks} specific subtasks that can be implemented one by one.
Task ID: ${task.id}
Title: ${task.title}
Description: ${task.description || 'No description provided'}
Current details: ${task.details || 'No details provided'}
${additionalContext ? `\nAdditional context to consider: ${additionalContext}` : ''}
${taskAnalysis ? `\nComplexity analysis: This task has a complexity score of ${taskAnalysis.complexityScore}/10.` : ''}
${taskAnalysis && taskAnalysis.reasoning ? `\nReasoning for complexity: ${taskAnalysis.reasoning}` : ''}
Subtasks should:
1. Be specific and actionable implementation steps
2. Follow a logical sequence
3. Each handle a distinct part of the parent task
4. Include clear guidance on implementation approach
5. Have appropriate dependency chains between subtasks
6. Collectively cover all aspects of the parent task
Return exactly ${numSubtasks} subtasks with the following JSON structure:
[
{
"id": 1,
"title": "First subtask title",
"description": "Detailed description",
"dependencies": [],
"details": "Implementation details"
},
...more subtasks...
]
Note on dependencies: Subtasks can depend on other subtasks with lower IDs. Use an empty array if there are no dependencies.`;
return basePrompt;
}
export default generateSubtaskPrompt;