fix(tags): Resolve critical tag deletion and migration notice bugs

Major Issues Fixed:

1. Tag Deletion Bug: Fixed critical issue where creating subtasks would delete other tags

   - Root cause: writeJSON function wasn't accepting projectRoot/tag parameters

   - Fixed writeJSON signature and logic to handle tagged data structure

   - Added proper merging of resolved tag data back into full tagged structure

2. Persistent Migration Notice: Fixed FYI notice showing after every command

   - Root cause: markMigrationForNotice was resetting migrationNoticeShown to false

   - Fixed migration logic to only trigger on actual legacy->tagged migrations

   - Added proper _rawTaggedData checks to prevent false migration detection

3. Data Corruption Prevention: Enhanced data integrity safeguards

   - Fixed writeJSON to filter out internal properties

   - Added automatic cleanup of rogue properties

   - Improved hasTaggedStructure detection logic

Commands Fixed: add-subtask, remove-subtask, and all commands now preserve tags correctly
This commit is contained in:
Eyal Toledano
2025-06-12 23:43:48 -04:00
parent b3ec151b27
commit 4585a6bbc7
9 changed files with 205 additions and 75 deletions

View File

@@ -1120,9 +1120,16 @@ function ensureAtLeastOneIndependentSubtask(tasksData) {
* This function is designed to be called after any task modification
* @param {Object} tasksData - The tasks data object with tasks array
* @param {string} tasksPath - Optional path to save the changes
* @param {string} projectRoot - Optional project root for tag context
* @param {string} tag - Optional tag for tag context
* @returns {boolean} - True if any changes were made
*/
function validateAndFixDependencies(tasksData, tasksPath = null) {
function validateAndFixDependencies(
tasksData,
tasksPath = null,
projectRoot = null,
tag = null
) {
if (!tasksData || !tasksData.tasks || !Array.isArray(tasksData.tasks)) {
log('error', 'Invalid tasks data');
return false;
@@ -1209,7 +1216,7 @@ function validateAndFixDependencies(tasksData, tasksPath = null) {
// Save changes if needed
if (tasksPath && changesDetected) {
try {
writeJSON(tasksPath, tasksData);
writeJSON(tasksPath, tasksData, projectRoot, tag);
log('debug', 'Saved dependency fixes to tasks.json');
} catch (error) {
log('error', 'Failed to save dependency fixes to tasks.json', error);