-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Labels
area:cliCLI functionalityCLI functionalityarea:task-managementCore task management featuresCore task management featuresbugSomething isn't workingSomething isn't workingmedium-priorityImportant but not urgentImportant but not urgent
Description
Summary
When using the set task command, each task number in tasks.json is saved as a string with quotes (e.g., "id": "3"). However, after running the update task command, the task number is saved as a number without quotes (e. g., "id": 3). This creates an inconsistent representation of task IDs in tasks.json.
Steps to Reproduce
- Use
set taskto add a task. Checktasks.json— task IDs are strings. - Use
update taskon a task. Checktasks.json— the task ID becomes a number.
Expected Behavior
Task IDs should always be consistently typed in tasks.json, as numbers (without quotes).
Actual Behavior
The type of id flips between string and number depending on which command last updated it.
Technical Details
- Core logic in
packages/tm-core/src/modules/storage/adapters/file-storage/file-storage.tscurrently stringifies task IDs before saving. - CLI script layer (
scripts/modules/utils.jsand related helpers) sometimes parses IDs as numbers before saving, especially when updating tasks. The functionnormalizeTaskIdsconverts IDs to numbers before passing upstream. - This inconsistency also exists in supporting tests, which sometimes expect numeric IDs, further propagating the problem.
- Merged or mutated objects with number-type IDs are occasionally written through to disk, bypassing the string normalization.
Suggested Fix
- Normalize task IDs as numbers everywhere: CLI, helpers, and tests should treat task IDs as numbers only.
- Remove string conversion in the
normalizeTaskIdsfunction inscripts/modules/utils.jsand enforce numeric type throughout. - Audit CLI scripts and helpers to ensure that all written IDs are serialized as numbers in storage.
- Make all relevant unit/integration tests expect numeric IDs.
- Add regression tests to enforce this contract.
References (Relevant Code Snippets Included)
- normalizeTaskIds (Example: scripts/modules/utils.js)
function normalizeTaskIds(tasks) {
if (!Array.isArray(tasks)) return;
tasks. forEach((task) => {
if (task.id !== undefined) {
// Should always coerce to number, NOT string
task.id = parseInt(task.id, 10);
}
// ...subtasks handling...
});
}- File storage adapter (Example: packages/tm-core/src/modules/storage/adapters/file-storage/file-storage.ts)
private normalizeTaskIds(tasks: Task[]): Task[] {
return tasks.map((task) => ({
...task,
id: String(task. id), // <--- This should be changed to a number, not string
// (rest of the object)
}));
}- Test expectation (should expect numbers)
expect(objectContaining({ id: 2, status: 'done' }))Metadata
Metadata
Assignees
Labels
area:cliCLI functionalityCLI functionalityarea:task-managementCore task management featuresCore task management featuresbugSomething isn't workingSomething isn't workingmedium-priorityImportant but not urgentImportant but not urgent
Projects
Status
Triage