diff --git a/scripts/modules/task-manager/add-task.js b/scripts/modules/task-manager/add-task.js index 61288c57..324dc39e 100644 --- a/scripts/modules/task-manager/add-task.js +++ b/scripts/modules/task-manager/add-task.js @@ -22,8 +22,7 @@ import { truncate, ensureTagMetadata, performCompleteTagMigration, - markMigrationForNotice, - normalizeTaskIds + markMigrationForNotice } from '../utils.js'; import { generateObjectService } from '../ai-services-unified.js'; import { getDefaultPriority } from '../config-manager.js'; @@ -70,7 +69,6 @@ function getAllTasks(rawData) { rawData[tagName] && Array.isArray(rawData[tagName].tasks) ) { - normalizeTaskIds(rawData[tagName].tasks); allTasks = allTasks.concat(rawData[tagName].tasks); } } @@ -308,8 +306,6 @@ async function addTask( // Find the highest task ID *within the target tag* to determine the next ID const tasksInTargetTag = rawData[targetTag].tasks; - - normalizeTaskIds(tasksInTargetTag); const highestId = tasksInTargetTag.length > 0 ? Math.max(...tasksInTargetTag.map((t) => t.id)) diff --git a/scripts/modules/task-manager/move-task.js b/scripts/modules/task-manager/move-task.js index f1e41d0b..fc82112f 100644 --- a/scripts/modules/task-manager/move-task.js +++ b/scripts/modules/task-manager/move-task.js @@ -1,5 +1,5 @@ import path from 'path'; -import { log, readJSON, writeJSON, setTasksForTag, normalizeTaskIds } from '../utils.js'; +import { log, readJSON, writeJSON, setTasksForTag } from '../utils.js'; import { isTaskDependentOn } from '../task-manager.js'; import generateTaskFiles from './generate-task-files.js'; @@ -79,8 +79,6 @@ async function moveTask( // Get the tasks for the current tag const tasks = rawData[tag].tasks; - - normalizeTaskIds(tasks); log( 'info', diff --git a/scripts/modules/task-manager/set-task-status.js b/scripts/modules/task-manager/set-task-status.js index 630518fc..18c18ced 100644 --- a/scripts/modules/task-manager/set-task-status.js +++ b/scripts/modules/task-manager/set-task-status.js @@ -7,8 +7,7 @@ import { readJSON, writeJSON, findTaskById, - ensureTagMetadata, - normalizeTaskIds + ensureTagMetadata } from '../utils.js'; import { displayBanner } from '../ui.js'; import { validateTaskDependencies } from '../dependency-manager.js'; @@ -77,8 +76,6 @@ async function setTaskStatus(tasksPath, taskIdInput, newStatus, options = {}) { tag, _rawTaggedData: rawData }; - - normalizeTaskIds(data.tasks); if (!data || !data.tasks) { throw new Error(`No valid tasks found in ${tasksPath}`); diff --git a/scripts/modules/utils.js b/scripts/modules/utils.js index 2ae216ae..aab7fd0f 100644 --- a/scripts/modules/utils.js +++ b/scripts/modules/utils.js @@ -282,9 +282,16 @@ function normalizeTaskIds(tasks) { if (Array.isArray(task.subtasks)) { task.subtasks.forEach(subtask => { if (subtask.id !== undefined) { - const parsedSubtaskId = parseInt(subtask.id, 10); - if (!isNaN(parsedSubtaskId) && parsedSubtaskId > 0) { - subtask.id = parsedSubtaskId; + // Check for dot notation (which shouldn't exist in storage) + if (typeof subtask.id === 'string' && subtask.id.includes('.')) { + // Extract the subtask part after the dot + const parts = subtask.id.split('.'); + subtask.id = parseInt(parts[parts.length - 1], 10); + } else { + const parsedSubtaskId = parseInt(subtask.id, 10); + if (!isNaN(parsedSubtaskId) && parsedSubtaskId > 0) { + subtask.id = parsedSubtaskId; + } } } }); @@ -432,6 +439,13 @@ function readJSON(filepath, projectRoot = null, tag = null) { // Store reference to the raw tagged data for functions that need it const originalTaggedData = JSON.parse(JSON.stringify(data)); + + // Normalize IDs in all tags before storing as originalTaggedData + for (const tagName in originalTaggedData) { + if (originalTaggedData[tagName] && Array.isArray(originalTaggedData[tagName].tasks)) { + normalizeTaskIds(originalTaggedData[tagName].tasks); + } + } // Check and auto-switch git tags if enabled (for existing tagged format) // This needs to run synchronously BEFORE tag resolution