This commit implements AI usage telemetry for the `expand-all-tasks` command/tool and refactors its CLI output for clarity and consistency. Key Changes: 1. **Telemetry Integration for `expand-all-tasks` (Subtask 77.8):**\n - The `expandAllTasks` core logic (`scripts/modules/task-manager/expand-all-tasks.js`) now calls the `expandTask` function for each eligible task and collects the individual `telemetryData` returned.\n - A new helper function `_aggregateTelemetry` (in `utils.js`) is used to sum up token counts and costs from all individual expansions into a single `telemetryData` object for the entire `expand-all` operation.\n - The `expandAllTasksDirect` wrapper (`mcp-server/src/core/direct-functions/expand-all-tasks.js`) now receives and passes this aggregated `telemetryData` in the MCP response.\n - For CLI usage, `displayAiUsageSummary` is called once with the aggregated telemetry. 2. **Improved CLI Output for `expand-all`:**\n - The `expandAllTasks` core function now handles displaying a final "Expansion Summary" box (showing Attempted, Expanded, Skipped, Failed counts) directly after the aggregated telemetry summary.\n - This consolidates all summary output within the core function for better flow and removes redundant logging from the command action in `scripts/modules/commands.js`.\n - The summary box border is green for success and red if any expansions failed. 3. **Code Refinements:**\n - Ensured `chalk` and `boxen` are imported in `expand-all-tasks.js` for the new summary box.\n - Minor adjustments to logging messages for clarity.
97 lines
3.3 KiB
JavaScript
97 lines
3.3 KiB
JavaScript
/**
|
|
* Direct function wrapper for expandAllTasks
|
|
*/
|
|
|
|
import { expandAllTasks } from '../../../../scripts/modules/task-manager.js';
|
|
import {
|
|
enableSilentMode,
|
|
disableSilentMode
|
|
} from '../../../../scripts/modules/utils.js';
|
|
import { createLogWrapper } from '../../tools/utils.js';
|
|
|
|
/**
|
|
* Expand all pending tasks with subtasks (Direct Function Wrapper)
|
|
* @param {Object} args - Function arguments
|
|
* @param {string} args.tasksJsonPath - Explicit path to the tasks.json file.
|
|
* @param {number|string} [args.num] - Number of subtasks to generate
|
|
* @param {boolean} [args.research] - Enable research-backed subtask generation
|
|
* @param {string} [args.prompt] - Additional context to guide subtask generation
|
|
* @param {boolean} [args.force] - Force regeneration of subtasks for tasks that already have them
|
|
* @param {string} [args.projectRoot] - Project root path.
|
|
* @param {Object} log - Logger object from FastMCP
|
|
* @param {Object} context - Context object containing session
|
|
* @returns {Promise<{success: boolean, data?: Object, error?: {code: string, message: string}}>}
|
|
*/
|
|
export async function expandAllTasksDirect(args, log, context = {}) {
|
|
const { session } = context; // Extract session
|
|
// Destructure expected args, including projectRoot
|
|
const { tasksJsonPath, num, research, prompt, force, projectRoot } = args;
|
|
|
|
// Create logger wrapper using the utility
|
|
const mcpLog = createLogWrapper(log);
|
|
|
|
if (!tasksJsonPath) {
|
|
log.error('expandAllTasksDirect called without tasksJsonPath');
|
|
return {
|
|
success: false,
|
|
error: {
|
|
code: 'MISSING_ARGUMENT',
|
|
message: 'tasksJsonPath is required'
|
|
}
|
|
};
|
|
}
|
|
|
|
enableSilentMode(); // Enable silent mode for the core function call
|
|
try {
|
|
log.info(
|
|
`Calling core expandAllTasks with args: ${JSON.stringify({ num, research, prompt, force, projectRoot })}`
|
|
);
|
|
|
|
// Parse parameters (ensure correct types)
|
|
const numSubtasks = num ? parseInt(num, 10) : undefined;
|
|
const useResearch = research === true;
|
|
const additionalContext = prompt || '';
|
|
const forceFlag = force === true;
|
|
|
|
// Call the core function, passing options and the context object { session, mcpLog, projectRoot }
|
|
const result = await expandAllTasks(
|
|
tasksJsonPath,
|
|
numSubtasks,
|
|
useResearch,
|
|
additionalContext,
|
|
forceFlag,
|
|
{ session, mcpLog, projectRoot }
|
|
);
|
|
|
|
// Core function now returns a summary object including the *aggregated* telemetryData
|
|
return {
|
|
success: true,
|
|
data: {
|
|
message: `Expand all operation completed. Expanded: ${result.expandedCount}, Failed: ${result.failedCount}, Skipped: ${result.skippedCount}`,
|
|
details: {
|
|
expandedCount: result.expandedCount,
|
|
failedCount: result.failedCount,
|
|
skippedCount: result.skippedCount,
|
|
tasksToExpand: result.tasksToExpand
|
|
},
|
|
telemetryData: result.telemetryData // Pass the aggregated object
|
|
}
|
|
};
|
|
} catch (error) {
|
|
// Log the error using the MCP logger
|
|
log.error(`Error during core expandAllTasks execution: ${error.message}`);
|
|
// Optionally log stack trace if available and debug enabled
|
|
// if (error.stack && log.debug) { log.debug(error.stack); }
|
|
|
|
return {
|
|
success: false,
|
|
error: {
|
|
code: 'CORE_FUNCTION_ERROR', // Or a more specific code if possible
|
|
message: error.message
|
|
}
|
|
};
|
|
} finally {
|
|
disableSilentMode(); // IMPORTANT: Ensure silent mode is always disabled
|
|
}
|
|
}
|