fix: normalize task IDs to numbers on load to fix comparison issues
- Added normalizeTaskIds function to convert string IDs to numbers - Applied normalization in readJSON for all code paths - Fixed set-task-status, add-task, and move-task to normalize IDs when working with raw data - Exported normalizeTaskIds function for use in other modules - Added test case for string ID normalization 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
committed by
Ralph Khreish
parent
077cbb99de
commit
ef23beac0d
@@ -22,7 +22,8 @@ import {
|
||||
truncate,
|
||||
ensureTagMetadata,
|
||||
performCompleteTagMigration,
|
||||
markMigrationForNotice
|
||||
markMigrationForNotice,
|
||||
normalizeTaskIds
|
||||
} from '../utils.js';
|
||||
import { generateObjectService } from '../ai-services-unified.js';
|
||||
import { getDefaultPriority } from '../config-manager.js';
|
||||
@@ -69,6 +70,7 @@ function getAllTasks(rawData) {
|
||||
rawData[tagName] &&
|
||||
Array.isArray(rawData[tagName].tasks)
|
||||
) {
|
||||
normalizeTaskIds(rawData[tagName].tasks);
|
||||
allTasks = allTasks.concat(rawData[tagName].tasks);
|
||||
}
|
||||
}
|
||||
@@ -306,6 +308,8 @@ 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))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import path from 'path';
|
||||
import { log, readJSON, writeJSON, setTasksForTag } from '../utils.js';
|
||||
import { log, readJSON, writeJSON, setTasksForTag, normalizeTaskIds } from '../utils.js';
|
||||
import { isTaskDependentOn } from '../task-manager.js';
|
||||
import generateTaskFiles from './generate-task-files.js';
|
||||
|
||||
@@ -79,6 +79,8 @@ async function moveTask(
|
||||
|
||||
// Get the tasks for the current tag
|
||||
const tasks = rawData[tag].tasks;
|
||||
|
||||
normalizeTaskIds(tasks);
|
||||
|
||||
log(
|
||||
'info',
|
||||
|
||||
@@ -7,7 +7,8 @@ import {
|
||||
readJSON,
|
||||
writeJSON,
|
||||
findTaskById,
|
||||
ensureTagMetadata
|
||||
ensureTagMetadata,
|
||||
normalizeTaskIds
|
||||
} from '../utils.js';
|
||||
import { displayBanner } from '../ui.js';
|
||||
import { validateTaskDependencies } from '../dependency-manager.js';
|
||||
@@ -76,6 +77,8 @@ 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}`);
|
||||
|
||||
@@ -529,6 +529,7 @@ function readJSON(filepath, projectRoot = null, tag = null) {
|
||||
// If anything goes wrong, try to return master or empty
|
||||
const masterData = data.master;
|
||||
if (masterData && masterData.tasks) {
|
||||
normalizeTaskIds(masterData.tasks);
|
||||
return {
|
||||
...masterData,
|
||||
_rawTaggedData: originalTaggedData
|
||||
@@ -1448,5 +1449,6 @@ export {
|
||||
createStateJson,
|
||||
markMigrationForNotice,
|
||||
flattenTasksWithSubtasks,
|
||||
ensureTagMetadata
|
||||
ensureTagMetadata,
|
||||
normalizeTaskIds
|
||||
};
|
||||
Reference in New Issue
Block a user