This document outlines the implementation of bidirectional synchronization between TaskMaster AI and Monday.com, focusing on the automatic recreation of items deleted in either system.
-
Push Sync (TaskMaster → Monday)
- Automatically recreates Monday.com items that were deleted but still exist in TaskMaster
- Updates tasks.json with new Monday item IDs when items are recreated
- Provides clear reporting of recreated items
-
Pull Sync (Monday → TaskMaster)
- Automatically recreates local tasks that exist in Monday.com but were deleted locally
- Supports a configuration option to control automatic recreation behavior
- Properly handles potential conflicts during recreation
-
Item Existence Check
- Enhanced the
syncTaskfunction to check if a Monday item exists before updating it - Added logic to handle the case when a Monday item referenced by a task no longer exists
- Implemented error handling to detect "not found" errors and trigger recreation
- Enhanced the
-
Recreation Logic
- Modified the sync process to recreate Monday items when the corresponding item ID is no longer valid
- Added a new result category
recreatedto track items that were recreated - Preserved the relationship between tasks and Monday items by updating the task's Monday item ID
-
Results Tracking
- Added a
recreatedarray to the results object to track recreated items - Enhanced the formatted output to show recreated items with their old and new Monday IDs
- Updated summary counts to include recreated items
- Added a
-
Missing Task Detection
- Enhanced the
compareItemsWithTasksfunction to identify tasks that exist in Monday.com but not locally - Added a
recreateMissingTasksoption (defaulting to true) to control automatic recreation behavior - Implemented special handling for cases where a Monday item maps to a different task ID
- Enhanced the
-
Recreation Tracking
- Added a
recreatedItemsarray to store information about recreated tasks - Updated the sync results to include a
recreatedcount and detailed information - Enhanced the formatted output to show recreated tasks
- Added a
-
Conflict Resolution
- Added special handling for cases where a Monday item has a task ID that conflicts with existing tasks
- Implemented logic to detect and report these conflicts for manual resolution
- Preserved data integrity by avoiding overwrites of existing tasks
-
Error Handling
- Made
handleOrphanedTasksmore robust to handle undefined or invalid task objects - Improved error handling in
findOrphanedLocalTasksto manage sync state entries gracefully - Added more detailed error logging to help diagnose synchronization issues
- Made
-
Sync State Management
- Enhanced the sync state management to properly track recreated items
- Added cleanup of outdated sync state entries when items are recreated
- Improved the handling of orphaned items in both directions
-
CLI Improvements
- Updated the CLI interface to support the new recreation functionality
- Added support for
--recreate-missing-tasksand--no-recreate-missing-tasksflags - Enhanced result formatting to clearly show recreated items
The implementation includes test scripts to verify the bidirectional synchronization:
-
General Sync Test (
scripts/test-sync.js)- Tests basic push and pull synchronization
- Verifies that changes are properly synchronized in both directions
-
Recreation Test (
scripts/test-recreation.js)- Specifically tests the recreation functionality
- Simulates deletion in both systems and verifies automatic recreation
The bidirectional sync functionality can be configured through the following options:
-
Push Sync
deleteOrphaned: Controls whether orphaned Monday items should be deleted (default: true)
-
Pull Sync
recreateMissingTasks: Controls whether missing tasks should be automatically recreated (default: true)removeOrphaned: Controls whether orphaned local tasks should be removed (default: true)
const { createPushSync } = require('task-master-sync');
const pushSync = createPushSync(config);
const results = await pushSync.pushSync('tasks/tasks.json', {
deleteOrphaned: true
});
console.log(`Created: ${results.created.length}`);
console.log(`Updated: ${results.updated.length}`);
console.log(`Recreated: ${results.recreated.length}`);const { createPullSync } = require('task-master-sync');
const pullSync = createPullSync(config);
const results = await pullSync.pullSync({
recreateMissingTasks: true,
removeOrphaned: true
});
console.log(`New: ${results.newTasks}`);
console.log(`Updated: ${results.updatedTasks}`);
console.log(`Recreated: ${results.recreated}`);# Push sync with recreation
npx taskmaster-monday push
# Pull sync with recreation disabled
npx taskmaster-monday pull --no-recreate-missing-tasks- Fixed an issue where the system would sometimes create a
tasks.jsonfile in the project root instead of using the correct path at./tasks/tasks.json. - Updated the
DEFAULT_TASKS_PATHconstant intaskMasterIO.jsto use'tasks/tasks.json'instead of just'tasks.json'. - Modified test scripts to correctly respect the proper tasks file path.
- Ensured the
pushSyncfunction properly accepts options via an object parameter, including the correct tasks path.
- Fixed
findOrphanedLocalTasksfunction to usestateManager.readSyncState()instead of the non-existentgetSyncState()method. - Improved error handling for sync state operations to gracefully handle undefined or invalid state entries.
To ensure task files are always up-to-date, we've implemented automatic execution of the task-master generate command:
- When running
pushsync, the system automatically runstask-master generatebefore sending updates to Monday.com - This ensures all task markdown files are generated from the latest tasks.json data
- The integration can be disabled with the
--skip-generateflag:taskmaster-sync push --skip-generate - If the generate command fails, the sync operation continues with a warning
- When running
pullsync, the system automatically runstask-master generateafter updating tasks.json - This ensures all changes pulled from Monday.com are immediately reflected in markdown task files
- Can be disabled with the
--skip-generateflag:taskmaster-sync pull --skip-generate - Only runs when not in dry-run mode and when regeneration is enabled (
--regenerateflag, which is true by default)
- If the
task-mastercommand is not available, the sync operation continues with a warning - All output from the generate command is captured and displayed in verbose mode
- Command execution is designed to be non-blocking for the main sync operation
The bidirectional synchronization implementation ensures that tasks remain synchronized between TaskMaster AI and Monday.com even when items are deleted in either system. This significantly improves the robustness and reliability of the integration, reducing the need for manual intervention.