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,
|
truncate,
|
||||||
ensureTagMetadata,
|
ensureTagMetadata,
|
||||||
performCompleteTagMigration,
|
performCompleteTagMigration,
|
||||||
markMigrationForNotice
|
markMigrationForNotice,
|
||||||
|
normalizeTaskIds
|
||||||
} from '../utils.js';
|
} from '../utils.js';
|
||||||
import { generateObjectService } from '../ai-services-unified.js';
|
import { generateObjectService } from '../ai-services-unified.js';
|
||||||
import { getDefaultPriority } from '../config-manager.js';
|
import { getDefaultPriority } from '../config-manager.js';
|
||||||
@@ -69,6 +70,7 @@ function getAllTasks(rawData) {
|
|||||||
rawData[tagName] &&
|
rawData[tagName] &&
|
||||||
Array.isArray(rawData[tagName].tasks)
|
Array.isArray(rawData[tagName].tasks)
|
||||||
) {
|
) {
|
||||||
|
normalizeTaskIds(rawData[tagName].tasks);
|
||||||
allTasks = allTasks.concat(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
|
// Find the highest task ID *within the target tag* to determine the next ID
|
||||||
const tasksInTargetTag = rawData[targetTag].tasks;
|
const tasksInTargetTag = rawData[targetTag].tasks;
|
||||||
|
|
||||||
|
normalizeTaskIds(tasksInTargetTag);
|
||||||
const highestId =
|
const highestId =
|
||||||
tasksInTargetTag.length > 0
|
tasksInTargetTag.length > 0
|
||||||
? Math.max(...tasksInTargetTag.map((t) => t.id))
|
? Math.max(...tasksInTargetTag.map((t) => t.id))
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import path from 'path';
|
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 { isTaskDependentOn } from '../task-manager.js';
|
||||||
import generateTaskFiles from './generate-task-files.js';
|
import generateTaskFiles from './generate-task-files.js';
|
||||||
|
|
||||||
@@ -79,6 +79,8 @@ async function moveTask(
|
|||||||
|
|
||||||
// Get the tasks for the current tag
|
// Get the tasks for the current tag
|
||||||
const tasks = rawData[tag].tasks;
|
const tasks = rawData[tag].tasks;
|
||||||
|
|
||||||
|
normalizeTaskIds(tasks);
|
||||||
|
|
||||||
log(
|
log(
|
||||||
'info',
|
'info',
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import {
|
|||||||
readJSON,
|
readJSON,
|
||||||
writeJSON,
|
writeJSON,
|
||||||
findTaskById,
|
findTaskById,
|
||||||
ensureTagMetadata
|
ensureTagMetadata,
|
||||||
|
normalizeTaskIds
|
||||||
} from '../utils.js';
|
} from '../utils.js';
|
||||||
import { displayBanner } from '../ui.js';
|
import { displayBanner } from '../ui.js';
|
||||||
import { validateTaskDependencies } from '../dependency-manager.js';
|
import { validateTaskDependencies } from '../dependency-manager.js';
|
||||||
@@ -76,6 +77,8 @@ async function setTaskStatus(tasksPath, taskIdInput, newStatus, options = {}) {
|
|||||||
tag,
|
tag,
|
||||||
_rawTaggedData: rawData
|
_rawTaggedData: rawData
|
||||||
};
|
};
|
||||||
|
|
||||||
|
normalizeTaskIds(data.tasks);
|
||||||
|
|
||||||
if (!data || !data.tasks) {
|
if (!data || !data.tasks) {
|
||||||
throw new Error(`No valid tasks found in ${tasksPath}`);
|
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
|
// If anything goes wrong, try to return master or empty
|
||||||
const masterData = data.master;
|
const masterData = data.master;
|
||||||
if (masterData && masterData.tasks) {
|
if (masterData && masterData.tasks) {
|
||||||
|
normalizeTaskIds(masterData.tasks);
|
||||||
return {
|
return {
|
||||||
...masterData,
|
...masterData,
|
||||||
_rawTaggedData: originalTaggedData
|
_rawTaggedData: originalTaggedData
|
||||||
@@ -1448,5 +1449,6 @@ export {
|
|||||||
createStateJson,
|
createStateJson,
|
||||||
markMigrationForNotice,
|
markMigrationForNotice,
|
||||||
flattenTasksWithSubtasks,
|
flattenTasksWithSubtasks,
|
||||||
ensureTagMetadata
|
ensureTagMetadata,
|
||||||
|
normalizeTaskIds
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user